Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

variables

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?

like image 238
Adam Avatar asked Feb 06 '26 08:02

Adam


1 Answers

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.

like image 194
Oliver Charlesworth Avatar answered Feb 07 '26 22:02

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!