提问人:The AppeaRare 提问时间:6/23/2023 最后编辑:The AppeaRare 更新时间:6/23/2023 访问量:55
当以下行在 java 中运行\编译时,幕后会发生什么: (LinkedList<Dog>)(Object)(new LinkedList<Car>());?
What happens behind the scenes when the following line is running\compiling in java: (LinkedList<Dog>)(Object)(new LinkedList<Car>());?
问:
写作时:
LinkedList<Dog> dogList = (LinkedList<Dog>)(Object)(new LinkedList<Car>());
我没有得到ClassCastException,而不仅仅是写:
Dog dog = (Dog)(Object)(new Car());
为什么会有区别?(幕后发生了什么?
我认为这与 java 的泛型机制有关。
答: 暂无答案
评论