The limitation of Arrays.asList() is not true in Thinking in Java 4th Edition

Viewed 262

In this book, it says :

A limitation of Arrays.asList() is that it takes a best guess about the resulting type of the List, and doesn't pay attention to what you are assigning it to.

The book is Thinking in Java By Bruce Eckel

However, the following code is working fine, contrary to code shown in this book page 280

public class Main{

    public static void main(String[] args) {
        List<Snow> snow = Arrays.asList(new Light(), new Heavy());
    }
}
class Snow {}
class Powder extends Snow {}
class Light extends Powder {}
class Heavy extends Powder {}

Java 1.8 , IntelliJ, Windows 7 enter image description here

Any thoughts are appreciated.

1 Answers
Related