Array type conversion

Walter Bright newshound1 at digitalmars.com
Sat Apr 28 20:45:50 PDT 2007


James Dennett wrote:
> An array of (pointers/references to) derived is usable
> as an *immutable* array of base (for suitable English
> meaning of immutable, matching C++'s notion of the
> array (equivalently, the pointers it contains) being
> const.
> 
> Java has runtime checks required because it allows
> conversion from array of Derived to array of Base,
> and that (as you know) also uses reference semantics.
> The conversion is widely viewed as a mistake in Java;
> if I pass a Derived[] around, the language should
> not silently allow one of its elements to refer to
> a Base object.

But a derived reference can always be implicitly converted to a base 
reference anyway. That's the point of polymorphism.



More information about the Digitalmars-d mailing list