Possible Duplicate:
What is a difference between <? super E> and <? extends E>?
Some Java programmers on a team I’m on are writing functions that return objects of type List<? extends T> to make read-only lists and return objects of type List<? super T> to make write-only lists.
In Java, what makes List<? extends T> read-only and List<? super T> write-only?
please read up on “producer extends, consumer super” (PECS) – I may need to do the same 🙂
Read only:
In case you would like to ensure that a method takes as a parameter a collection of items ( using generics) – when you use
List<? extends T>– the list can contain any subtype of T but cannot add to the collection since it does not know at runtime the specific type of T that the List contains.Write only:
For
List<? super T>, the list can contain T regardless of the actual parameterized type (using super will allow that to happen).Hope it helps.