本文介绍了空是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,null 是所有引用类型 TT 实例.

As I understood null is instance of T for all reference type T.

问题 1.null 的定义是什么?null 在内存中如何表示?

Question 1. What's defenition of null? How does null represents in memory?

考虑以下情况:我们定义了类

Consider the following case:We defined class

public class MyClass{
    Integer i;
}

现在 null 可以转换为 MyClass,但我没有明确定义.

Now null can be cast to MyClass, but I don't explicitly define that.

问题 2. 哪个编译器会知道 null 可以转换为 MyClass?

Question 2. From what compiler will be know that null can be cast to MyClass?

推荐答案

形式上,nullnull 类型的单例成员,定义为子类型其他所有 Java 类型.

Formally, null is a singleton member of the null type, which is defined to be the subtype of every other Java type.

null 是一个引用类型,它的值是唯一不引用任何对象的引用值.因此,内存中没有 null 的表示.值为 null 的引用类型变量的二进制值只是零(全零位).尽管没有明确指定,但它遵循对象的一般初始化语义,任何其他值都会给实现带来重大问题.

null is a reference type and its value is the only reference value which doesn't refer to any object. Therefore there is no representation of null in memory. The binary value of a reference-typed variable whose value is null is simply zero (all zero bits). Even though this is not explicitly specified, it follows from the general initialization semantics of objects and any other value would cause major problems to an implementation.

这篇关于空是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:47