I would like some version of this code to compile in java.
class X
{
List<X> getvalue(){...};
}
class Y extends X
{
List<Y> getvalue(){...};
}
Javac (1.6) returns an error because List <Y> and List <X> are incompatible.
The thing is, I would like the compiler to recognize that List <Y> is a compatible return of type to List <X> if Y is a subtype of X. The reason I want this is to make it easier to use a custom factory class.
Note. This question is somewhat reminiscent of
this question
but for java.
source
share