I was reading about generics and I did not understand the need for unbound wildcards and how it differs from raw type. I read this question but still did not get it clearly.
How
List>
differs fromList
The main difference is that the first line compiles but the second does not:
List> list = new ArrayList ();
List
However, because you don't know what the generic type of List>
is, you can't use its parameterized methods:
List> list = new ArrayList ();
list.add("aString"); //does not compile - we don't know it is a List
list.clear(); //this is fine, does not depend on the generic parameter type
As for the difference with raw types (no generics), the code below compiles and runs fine:
List list = new ArrayList ();
list.add("aString");
list.add(10);