Can someone explained, as detailed as possible, the differences between the following types?
List
List
Let me m
In my own simple terms:
List
Would declare an ordinary collection, can hold any type, and will always return Object.
List
Will create a list that can hold any type of object, but can only get assigned a another List
For instance this doesn't work;
List
Of course you can add anything but only can pull Object.
List
Finally
List>
Will let you assign any type, including
List > l = new ArrayList();
List > l2 = new ArrayList();
This would be called collection of unknown and since the common denominator of unknown is Object you will be able to fetch Objects ( a coincidence )
The importance of unknown comes when its used with subclassing:
List extends Collection> l = new ArrayList(); // compiles
List extends Collection> l = new ArrayList(); // doesn't,
// because String is not part of *Collection* inheritance tree.
I hope using Collection as the type doesn't create confusion, that was the only tree that came to my mind.
The difference here, is that l is a collection of unknow that belongs to the Collection hierarchy.