Java · Hard
What are covariance and contravariance in Java generics? Why is List<Dog> not a List<Animal>?
JavaCore Java
Answer preview
Covariance — If Dog extends Animal, then List<Dog> should be a subtype of List<Animal> — but in Java, it is NOT.…