简体   繁体   English

是否可以为值分配或与值类型变量进行比较?

[英]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. 值类型变量是valuenull是任何值的absense。 So null and value types are incompatible by definition. 因此, null和值类型根据定义是不兼容的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可以在Java中为变量分配其他类型吗? - Can a variable be assigned different type in java? 在数据竞争期间,线程是否可以读取volatile变量的初始空值? 特别是在构造函数中为它赋给非null值时? - During a data race can a thread ever read initial null value of volatile variable? especially when a non null value is assigned to it in constructor? 从未分配null的volatile变量可以包含null吗? - Can a volatile variable that is never assigned null to ever contain null? 可以将WHat值分配给此类的变量 - WHat value can be assigned to this class's variable 在hibernate查询执行时,是否将空值赋给基本类型的属性? - Null value was assigned to a property of primitive type while hibernate query execution? org.hibernate.PropertyAccessException:空值已分配给布尔类型的属性 - org.hibernate.PropertyAccessException: Null value was assigned to a property of boolean type 清单 <Class> 变量即使分配了值也返回null - List<Class> variable returns null even when assigned a value null值无法分配给基本类型错误(Spring / Hibernate) - A null value cannot be assigned to a primitive type error (Spring/Hibernate) hibernate异常将空值赋给基本类型setter的属性 - hibernate exception Null value was assigned to a property of primitive type setter 为什么不能将int与null进行比较,但可以将Integer与null进行比较 - why int can't be compared to null but Integer can be compared to null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM