Generics references
- From: "jupiter" <jupiter49byebyeSpam@xxxxxxx>
- Date: Mon, 28 May 2007 13:28:02 -0400
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?
.
- Follow-Ups:
- Re: Generics references
- From: Mark Rafn
- Re: Generics references
- Prev by Date: Collections.class methods anachronisms?
- Next by Date: Re: returning a generic array
- Previous by thread: Collections.class methods anachronisms?
- Next by thread: Re: Generics references
- Index(es):