saima kanwal wrote:well for a detailed explanation and concept building, i would suggest you to read the chapter of Collections and Generics from K & B thoroughly.
Yeah i have gone through the chapters. But its a bit confusing.
saima kanwal wrote:As for the first code, <? extends Number> means any class that is a subclass of class Number can come here. Since Integer is a subclass of Number , and list2 is a List of type Integer , list1 = list2 will compile without any errors.
for the second code , list one is defined to be of type Integer ( a fixed definite type) so any list of only the type Integer can be assigned to it. but on the right hand side we find that , we get list of type <? extends Number> so compilation fails.
Thanks for the explanation. Just cleared the confusion