Howdy y'all!
Let me get straight to the point:
Tried to compile on
java 1.5.11 and got the following error message:
Type mismatch: cannot convert from List<capture-of ? super Number> to List<Number>
But wait - the fun's only about to begin
Change the types of both
output and
input reference variables to List<Number> - You'll get the same stuff.
Change
output to List<Number> and
input to List<Integer> - same stuff.
TYhe problem is in the return type.
Let's analyse that:
1.)
E is any type that passes IS-A
test for being a Number.
Both Number and Integer play along, so if we're either passing a list of Numbers or a list of Integers as a method's param - it's OK.
2.) The return type is something that is a supertype to the type we passed.
So if I passed a list of Integers, I would expect to be able to assign the returned reference to the reference types: List<Object>, List<Number> or List <Integer>.
If I was to pass a list of Numbers, I would expect the compiler would let me assign the returned value to the reference types: List<Object> and List<Number>.
But instead - I get that weird looking error message. I checked the same with 'extends' frame - same thing.
Does it mean that I can't specify 'fuzzy' generic return types - only the solid ones?
I'm looking forth to Your feedback.
Cheers,
Paksas