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.
Yours, Bu.
Lucky J Verma
Ranch Hand
Joined: Apr 11, 2007
Posts: 277
posted
0
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
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.