When you have a List<?> then it is read-only. You cannot add anything to that list, because it is not sure what parameterized type it actually has.
Lucky J Verma
Joined: Apr 11, 2007
Compiler Error 1 comes because you declared list as List<?> which says list of any type.In wild cards,we canont anything except null. So add(object) fails
Compiler warning 2 comes because method2()called is adding something to the generic-based list.Here whenever generic -code is mixed with non-generics code and you try to add something ,which is legal and can fail later,compiler warnings. Check K & B SCJP pg 576