When you look further, you will find that the fathers of the Java language later decided to create no Generics covariance . And this is for good reason.
Because it is List<Apple>not List<Fruit>. Otherwise, you could do something like
List<Apple> apples = new ArrayList<>();
List<Fruit> fruits = apples;
fruits.add(new Banana());
but don't you expect that
Apple badApple = apples.get(0);
- safe call? If you allow covariance here, it is not!
And with surprise: what a problem in Java arrays!
Therefore it is really a problem that Java arrays are covariant! And it's better that Scala arrays actually allow you to precisely control your βvarianceβ. In Scala, you have full control over dispersion; whereas in Java they are always covariant.
"" , sort(Object[] objects) , - Java. 20 . "" , : -.
"" , Java ArrayStoreException. , Java- !