[Issue 2095] covariance w/o typechecks = bugs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 21 17:28:01 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=2095



--- Comment #24 from Stewart Gordon <smjg at iname.com> 2010-11-21 17:26:38 PST ---
(In reply to comment #23)
> >   <? extends A>[]
> 
> Interesting. This type implies array is mutable, so you can put objects into
> it.

No, because you don't know which subclass of A the particular array is of. 
Java does exactly this with its generics - prevents you at compile-time from
putting objects into the data structure for this reason.  All Java generics do
is compile-time type checking - at run-time, a List is a List.  But arrays are
different.

But each element of the array is mutable.

> Java will check at runtime for array type, but in D arrays don't have rtti.

Yes, because Java arrays don't use generics.  Probably for backward
compatibility, since they were invented long before generics were.  They're
just convertible to arrays of any class higher up the hierarchy.  This has been
claimed as one of the main weaknesses of Java's design.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list