Covariance and Invariance
About
Covariance
Example: Covariance in Arrays
String[] strings = {"one", "two"};
Object[] objects = strings; // Allowed due to covarianceObject[] objects = strings;ava
objects[0] = 10; // ArrayStoreException at runtimeCovariance in Generics
List<? extends Number> numbers = new ArrayList<Integer>();Invariance
Comparison Table
Last updated