gpt4 book ai didi

java - Arrays.asList() 的限制在 Thinking in Java 4th Edition 中不成立

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:46:24 26 4
gpt4 key购买 nike

<分区>

在这本书中,它说:

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.

这本书是 Bruce Eckel 的 Thinking in Java

然而,下面的代码工作正常,与本书第 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

如有任何想法,我们将不胜感激。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com