java Java中的null == false吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30234231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is null == false in Java?
提问by Babken Vardanyan
Does the following expression evaluate to true or false in Java?
以下表达式在 Java 中的计算结果为 true 还是 false?
null == false
I can't find any information about this on the internet.
我在互联网上找不到任何关于此的信息。
Note that this questionis about wrapped Boolean
value, and not about primitive boolean
/true
/false
.
请注意,这个问题是关于包裹Boolean
价值,而不是原始boolean
/ true
/ false
。
回答by GiantTree
You can't compare null
to a boolean
.
They are different types one indicating a null reference pointerand the other one a false/not truevalue.
你不能比较null
的boolean
。
它们是不同的类型,一种表示空引用指针,另一种表示假/非真值。
Thus the answer is: No this expression is not even valid and if it was, it would be false.
因此答案是:不,这个表达式甚至是无效的,如果是,它将是错误的。
回答by Kapcash
The null
key word presents a pointer which point... nowhere. Which means Java can't get the value in the memory by it's index.
该null
关键字的礼物一个指针,它指向...无门。这意味着 Java 无法通过索引获取内存中的值。
A boolean
is a memory value of 1 bit, 0 is false and 1 is true (or inverse). The value is get with the pointing indexof the variable (if this boolean is stock in such a variable)
Aboolean
是 1 位的内存值,0 为假,1 为真(或相反)。该值是通过变量的指向索引获得的(如果这个布尔值在这样的变量中是存货)
You can't checkan equality between something representing nothing and a one bit value. Your line will throw an error !
您无法检查不表示任何内容和一位值之间的相等性。你的线路会抛出错误!
Before ask, you should try this out yourself !
在询问之前,您应该自己尝试一下!
回答by Lauris01
null and false is not comparable
null 和 false 没有可比性
回答by Chickenturtle
it gives The operator == is undefined for the argument type(s) null, boolean error
它给出了参数类型的运算符 == 未定义 null,布尔错误
you can compare false == false or null == null;
您可以比较 false == false 或 null == null;