/** * Generics are not covariant in Java * Another example of the problems that covariant generics * could cause were it allowed * * @author gtowell * created July 2022 */ import java.util.ArrayList; public class Cov1 { public static void main(String[] args) { ArrayList ali = new ArrayList<>(); //ArrayList aln = ali; // will not compile //aln.add(Double.valueOf(4.5)); ArrayList[] alia = new ArrayList[4]; Object[] oa = alia; ArrayList alii = new ArrayList(); alii.add(3); oa[0] = alii; String s = alia[0].get(0); } }