java generics covariance

Posted by soocracy42 on Stack Overflow See other posts from Stack Overflow or by soocracy42
Published on 2010-04-18T02:09:42Z Indexed on 2010/04/18 2:13 UTC
Read the original article Hit count: 521

Filed under:
|
|
|

I am having trouble understanding the following article: http://www.ibm.com/developerworks/java/library/j-jtp01255.html

Under,

Generics are not covariant

the author states,

Because ln is a List, adding a Float to it seems perfectly legal. But if ln were aliased with li, then it would break the type-safety promise implicit in the definition of li -- that it is a list of integers, which is why generic types cannot be covariant.

I can't understand the part where it says "if ln were aliased with li". What does the author means by alias?(reference?). The code snippet above the quoted line seems to illustrate WHAT is illegal in java and not WHY. It would be very helpful to me if somebody could explain with an example. Thanks in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about alias