I read in a book (Thinking in Java by Bruce Eckel, 4th edition, page 47) that null
is equal to '\u000'
. And then I was wondering what exactly does '\u000'
really mean.
我在一本书(布鲁斯·埃克尔的《用Java思考》,第4版,第47页)中读到null等于'\u000'。然后我想知道“\u000”到底是什么意思。
As per my understanding null was nothing or absence of anything. And '\u000'
comes in contradiction with this definition.
根据我的理解,零是没有或没有任何东西。而‘\u000’则与这个定义相矛盾。
Can anyone clarify this issue about null
and '\u000'
?
谁能澄清关于null和'\u000'的问题吗?
4 个解决方案
#1
14
The language specification is where null is defined, and it says
语言规范是定义null的地方,它说
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. --Link to documentation (Section 4.1)
还有一个特殊的空类型,表达式null的类型,它没有名称。因为空类型没有名称,所以不可能声明空类型的变量或强制转换为空类型。空引用是空类型表达式的唯一可能值。空引用总是可以被转换为任何引用类型。在实践中,程序员可以忽略null类型,并假设null只是一个特殊的文字,可以是任何引用类型。——链接到文档(第4.1条)
and
和
The null type has one value, the null reference, represented by the literal null, which is formed from ASCII characters. A null literal is always of the null type. --Link to documentation (Section 2.3)
null类型有一个值,即null引用,由文字null表示,它是由ASCII字符组成的。空文字总是属于空类型。——链接到文档(第2.3节)
Rather a circular sounding definition, but the value of null
is the null reference itself - just another pointer. The value of the null reference isn't really relevant and is presumably up to the implementor, but zero or some other value that can't be confused with another object address is likely.
这是一个循环的定义,但null的值本身就是空引用——只是另一个指针。空引用的值并不是真正相关的,可能取决于实现者,但是0或其他不能与另一个对象地址混淆的值是可能的。
Confusion may be caused here because there is a character value called the null character with value \u0000
. This is the default value for type char.
这里可能会出现混乱,因为有一个名为null的字符值,值为\u0000。这是类型char的默认值。
#2
5
\u000
would be the unicode representation of a character with ASCII code 0, but has nothing to do with null
as used by Java.
\u000将是ASCII码0的字符的unicode表示形式,但与Java使用的null没有任何关系。
#3
4
'\u0000' decimal equivalent is 00 Char equivalent is NUL.
'\u0000'的十进制等价是00字符等价是NUL。
From Character in Javadoc: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html
来自Javadoc中的字符:http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html
static char MIN_VALUE
The constant value of this field is the smallest value of type char, '\u0000'.
This is the unicode value, that in CHAR is equivalent to NULL, ie it is the NULL CHARACTER, rather than being the literal NULL.
这是unicode的值,在CHAR是等价于NULL的,也就是空字符,而不是空字符。
#4
1
null
is a literal and you can see the specification which says in practice you can simply pretend that it's "merely a special literal that can be of any reference type".
null是一个文字,您可以看到在实践中说明的说明,您可以简单地假设它是“可以是任何引用类型的特殊文字”。
as @assylias said what you read was surely not out of java :)
正如@assylias所说,你读到的肯定不是出自java:)
#1
14
The language specification is where null is defined, and it says
语言规范是定义null的地方,它说
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. --Link to documentation (Section 4.1)
还有一个特殊的空类型,表达式null的类型,它没有名称。因为空类型没有名称,所以不可能声明空类型的变量或强制转换为空类型。空引用是空类型表达式的唯一可能值。空引用总是可以被转换为任何引用类型。在实践中,程序员可以忽略null类型,并假设null只是一个特殊的文字,可以是任何引用类型。——链接到文档(第4.1条)
and
和
The null type has one value, the null reference, represented by the literal null, which is formed from ASCII characters. A null literal is always of the null type. --Link to documentation (Section 2.3)
null类型有一个值,即null引用,由文字null表示,它是由ASCII字符组成的。空文字总是属于空类型。——链接到文档(第2.3节)
Rather a circular sounding definition, but the value of null
is the null reference itself - just another pointer. The value of the null reference isn't really relevant and is presumably up to the implementor, but zero or some other value that can't be confused with another object address is likely.
这是一个循环的定义,但null的值本身就是空引用——只是另一个指针。空引用的值并不是真正相关的,可能取决于实现者,但是0或其他不能与另一个对象地址混淆的值是可能的。
Confusion may be caused here because there is a character value called the null character with value \u0000
. This is the default value for type char.
这里可能会出现混乱,因为有一个名为null的字符值,值为\u0000。这是类型char的默认值。
#2
5
\u000
would be the unicode representation of a character with ASCII code 0, but has nothing to do with null
as used by Java.
\u000将是ASCII码0的字符的unicode表示形式,但与Java使用的null没有任何关系。
#3
4
'\u0000' decimal equivalent is 00 Char equivalent is NUL.
'\u0000'的十进制等价是00字符等价是NUL。
From Character in Javadoc: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html
来自Javadoc中的字符:http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html
static char MIN_VALUE
The constant value of this field is the smallest value of type char, '\u0000'.
This is the unicode value, that in CHAR is equivalent to NULL, ie it is the NULL CHARACTER, rather than being the literal NULL.
这是unicode的值,在CHAR是等价于NULL的,也就是空字符,而不是空字符。
#4
1
null
is a literal and you can see the specification which says in practice you can simply pretend that it's "merely a special literal that can be of any reference type".
null是一个文字,您可以看到在实践中说明的说明,您可以简单地假设它是“可以是任何引用类型的特殊文字”。
as @assylias said what you read was surely not out of java :)
正如@assylias所说,你读到的肯定不是出自java:)