简体   繁体   English

什么是未初始化的引用变量,它不为null

[英]What is a uninitialized reference variable when it's not null

In java, local reference variables do not have a default value of null before they are initialized. 在java中,本地引用变量在初始化之前没有默认值null。 What exactly is the difference between a variable with a value of null, and a variable with no value? 具有null值的变量和没有值的变量之间究竟有什么区别?

An uninitialized reference doesn't have no value, it has an undefined value (and the compiler prevents you from using them, IIRC). 未初始化的引用没有任何值,它具有未定义的值(并且编译器阻止您使用它们,IIRC)。 A reference initialized to null will result in a equality comparison with null always evaluating to true . 初始化为null的引用将导致与null的相等性比较,始终求值为true

In a less-restrictive language a variable that has not been somehow initialized can contain random data. 在限制较少的语言中,尚未以某种方式初始化的变量可以包含随机数据。

In Java an uninitialized variable cannot be referenced. 在Java中,无法引用未初始化的变量。 This is enforced by both the compiler and the bytecode verifier. 这由编译器和字节码验证器强制执行。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM