How come in java we cannot do:
List> aList = new ArrayList>();
Even though thi
You should definitely use the ? type wildcard when appropriate, do not avoid it as a general rule. For example:
public void doThingWithList(List> list);
allows you to pass a List or a List.
public void doThingWithList(List> list);
allows you to only pass arguments declared as List. A small distinction, yes, but using the wildcard is powerful and safe. Contrary to how it may seem, a List is not a subclass, or is not assignable, from List. Nor is List a subclass of List extends Number, which is why the code above does not compile.