So I was looking over some Java code and stumbled upon:
List extends SomeObject> l;
basically this list accepts all objects that ar
The key link you want to read is http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html which explains Generic wildcard in detail.
The List
is not the same as List extends SomeObject>
. Observe the following
List
You may want to observe that you can add say a String to both the x and the y list however it will be useful when you write say a library function (such as the printCollection in the example shown in the link) rather than accepting a Collection
in which case a user cannot pass his list of strings that he has to your method, if you accept Collection extends Object>
then the user can pass his Collection
etc without having to explicitly create another list.