Java guarantees that an assign to an array component preserves the general dynamic type of the array.

JAVA TO GO!
Arrays in Java: Second-class citizens?
Miguel Katrib Mora
Listing 1. Java guarantees that an assign to an array component preserves the general dynamic type of the array.


T[] x;
...
x = new T’[10];
/*legal, T’[] is a subtype of T[]
*/
...
T’ a = new T’();
x[k]=a;
/*legal T’ is the type of the components of x
*/
...
T y = new T();
x[i]=y;
/* illegal, a runtime exception will be thrown because x has
dynamic type T’[] and T does not
conform to T’
*/

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.