The last part makes sense, no?
If you could do
List<Fruit> fruits = apples
Then you could add an orange to the fruits list, and it would appear among the apples.
It doesn't seem like you can fix this without immutability?
List<Fruit> fruits = apples
Then you could add an orange to the fruits list, and it would appear among the apples.
It doesn't seem like you can fix this without immutability?
A type constructor of lists (which Java's standard library doesn't have to the best of my knowledge) is covariant on its element type, but a type constructor of mutable cells is invariant on its content type.
List<Apple> apples = aps
If you're using a general type Fruit, and can't stand any fruit that isn't an apple, you probably need to use the more specific Apple type.
The assignment sort of goes both ways like that.