Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33200

Generic cannot be applied

Newsgroups comp.lang.java.programmer
Date 2015-11-25 13:33 -0800
Message-ID <46618f03-00af-47fe-affa-5e12b9a2f4cc@googlegroups.com> (permalink)
Subject Generic cannot be applied
From Philipp Kraus <philipp.kraus.flashpixx@gmail.com>

Show all headers | View raw


Hello,

I have got these interface structure

public interface IVariable<T>
{

     public T get();
     public void set(T v);
}

public interface IOperator<T>
{
      public IVariable<T> evaluate( IVariable<T> p );
}


and I implement this class

public class myOperator<T extends Number> implements Operator<T>
{
      public IVariable<T> evaluate( IVariable<T> p )
      {
           p.set( new Double(p.get().doubleValue() + 1) );  <<<
           return p;
      }
}

The line with <<< create an compiler error  and I need to cast the new Double to T, but I don't understand, why I must cast. The error message is "IVariable<T> cannot be applied". IMHO a Double inherit from Number and T extends a Number on myOperator class, so an explicit cast is not needed.

Can anybody explain, why I need a cast at the point <<< ?

Thanks

Phil

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Generic cannot be applied Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-11-25 13:33 -0800
  Re: Generic cannot be applied Arne Vajhøj <arne@vajhoej.dk> - 2015-11-25 16:53 -0500
  Re: Generic cannot be applied Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-25 17:00 -0500
  Re: Generic cannot be applied Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2015-11-26 11:06 -0600

csiph-web