简体   繁体   中英

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. What exactly is the difference between a variable with a value of null, and a variable with no value?

An uninitialized reference doesn't have no value, it has an undefined value (and the compiler prevents you from using them, IIRC). A reference initialized to null will result in a equality comparison with null always evaluating to 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. This is enforced by both the compiler and the bytecode verifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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