[英]Can null be assigned to or be compared to a value type variable?
In Java, there have always existed primitive types and references, but not value types. 在Java中,始终存在原始类型和引用,但不存在值类型。
One of the goals of Project Valhalla is to explore and incubate feature candidates such as value types . Project Valhalla的目标之一是探索和孵化特征候选者,例如价值类型 。
I would like to know if null
can be assigned to a value type variable, or if a value type variable can be compared to null
. 我想知道是否可以将
null
赋给值类型变量,或者是否可以将值类型变量与null
进行比较。
If not, I would also like to know why. 如果没有,我也想知道原因。
From here: https://wiki.openjdk.java.net/display/valhalla/Minimal+Value+Types 从这里: https : //wiki.openjdk.java.net/display/valhalla/Minimal+Value+Types
Value types are "immutable, identity-agnostic, non-nullable, non-synchronizable, final" 值类型是“不可变的,身份不可知的,不可空的,不可同步的,最终的”
So no, it can't be null 所以不,它不能为空
Value type variable is value
, null
is absense of any value. 值类型变量是
value
, null
是任何值的absense。 So null
and value types are incompatible by definition. 因此,
null
和值类型根据定义是不兼容的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.