I am struggling to understand what the following statement achieves:
List aList = new ArrayList<String>();
It compiles successfully but it really doesn't provide and generic type protection at compile time. I can still add whatever I want to the list (Objects, Strings, Threads). Also the get() method of the newly created list still returns an object.
Obviously this is very different to:
List aList = new ArrayList<String>();
Here I am prevented from adding in the wrong objects and the get method retuns a String.
What is the point in adding the generic type to the reference and to the object as it seems to me (I am a newbie with generics) that the reference achieves everything. Are their any Collection methods which would be be affected by the first statement?
List aList = new ArrayList<String>();
It compiles successfully but it really doesn't provide and generic type protection at compile time. I can still add whatever I want to the list (Objects, Strings, Threads). Also the get() method of the newly created list still returns an object.
Obviously this is very different to:
List aList = new ArrayList<String>();
Here I am prevented from adding in the wrong objects and the get method retuns a String.
What is the point in adding the generic type to the reference and to the object as it seems to me (I am a newbie with generics) that the reference achieves everything. Are their any Collection methods which would be be affected by the first statement?