This is from Thinking in Java
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) {
//The book says it won't compile, but actually it does.
List<Snow> snow2 = Arrays.asList(new Light(), new Heavy());
}
}
Here is my Java enviroment:
- java version "1.8.0_60"
- Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
- Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
LightandHeavyare subclasses of Snow, and can therefore be added to aListofSnow.Type mismatch: cannot convert from List<Powder> to List<Snow>.