Can null be assigned to or be compared to a value type variable?

China☆狼群 提交于 2019-12-10 18:13:55

问题


In Java, there have always existed primitive types and references, but not value types.

One of the goals of Project Valhalla is to explore and incubate feature candidates such as value types.

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.

If not, I would also like to know why.


回答1:


From here: 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




回答2:


Value type variable is value, null is absense of any value. So null and value types are incompatible by definition.



来源:https://stackoverflow.com/questions/48694891/can-null-be-assigned-to-or-be-compared-to-a-value-type-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!