This
thread is supposed to be a little compendium about generics. There are lot's of fact and personally I am getting confused every time I don't see the generics for more than one week
Add here informations about generics but keep it short - don't put explanations, just facts. And don't forget about simple examples.
1. List<CharSequence>
It means that this list contains objects of class CharSequence.
We can retrieve only objects of class CharSequence from such List.
We can put only objects of CharSequence class into that List.
2. List<? super CharSequence>
It means that this list contains objects of either CharSequence or some class that is a superclass of CharSequence.
We cannot retrieve anything from such List.
We can put only objects of CharSequence class into that List.
3. List<? extends CharSequence>
It means that this list contains objects of some class that is either CharSequence or some subclass of CharSequence.
We can retrieve only objects of class CharSequence from such List.
We cannot put any objects into that List.
4. List<?>
It is the same as: List<? extends Object>.
It means that this list contains objects of some class that is either Object or some subclass of Object.
We can retrieve only objects of class Object from such List.
We cannot put any objects into that List.
[ May 19, 2008: Message edited by: Ismael Upright ]