|
|
|
|
|
by saghm
2092 days ago
|
|
Not GP, but there's a type unsoundness bug with the fact that you can assign an array of a subtype to an array of a super type (apologies if my syntax is off; I haven't written Java in a while): class Animal {}
class Cat extends Animal {}
class Dog extends Animal {} Animal[] cats = new Cat[1];
Animal dog = new Dog();
cats[0] = dog; This will compile fine but throw an error at runtime. The only possible way to avoid runtime errors with assigning a Cat array to an Animal array is if you only put Cats in it, at which point it would make more sense to just use a Cat array, so it would have been better design to make assigning a Cat array to an Animal array a compiler error. |
|