//: holding/AsListInference.java // Arrays.asList() makes its best guess about type. import java.util.*; class Snow {} class Powder extends Snow {} class Light extends Powder {} class Heavy extends Powder {} class Crusty extends Snow {} class Slush extends Snow {} public class AsListInference { public static void main(String[] args) { List snow1 = Arrays.asList( new Crusty(), new Slush(), new Powder()); // Won't compile: // List snow2 = Arrays.asList( // new Light(), new Heavy()); // Compiler says: // found : java.util.List // required: java.util.List // Collections.addAll() doesn't get confused: List snow3 = new ArrayList<>(); Collections.addAll(snow3, new Light(), new Heavy()); // Give a hint using an // explicit type argument specification: List snow4 = Arrays.asList( new Light(), new Heavy()); } } ///:~