|
|
|
|
|
by saghm
687 days ago
|
|
I can't speak for the others, but Java allows assigning arrays of subtypes to variables declared as an array of a supertype, which isn't sound: class A {}
class B1 extends A {}
class B2 extends A {}
A[] arr = new B1[1];
arr[0] = new B2();
In the above example only way that assigning an array of `B1` to a variable typed as an array of `A` is if only valid `B1` objects are ever put into it, at which point there's no reason not to just have the variable typed as a `B1` array. It still will compile fine though! |
|