Generics references



I've noticed that the type in generic declarations is not
"inherited" by new references to the object. This seems
inconsistent to me but maybe there's a good reason for it. To wit:

ArrayList<String> list1 = new ArrayList<String>();

ArrayList list2 = list;

list1.add(new Integer(3)); //compiler catches it as expected.
list2.add(new Integer(3)); //compiler is fat, dumb and happy.

I thought the idea of a reference was to point to the original
object and pick up all of the relevant data. Why not type?




.