gpt4 book ai didi

java - 为什么 null 被称为 "a subtype of every reference type"?

转载 作者:行者123 更新时间:2023-12-02 15:53:34 25 4
gpt4 key购买 nike

各位,谁能对我在 this book 中遇到的短语给出一个合乎逻辑的解释? :

You may find it helpful to think of ? extends T as containing every type in an interval bounded by the type of null below and by T above (where the type of null is a subtype of every reference type).

谢谢。

最佳答案

我认为这只是意味着您可以将空引用分配给任何引用类型。在我看来,这并不是一种非常有帮助的思考方式。

Java 语言规范对 null 类型有这样的规定(在 section 4.1 中):

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.

关于java - 为什么 null 被称为 "a subtype of every reference type"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3495711/

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