The int type variable is the primitive type variable. For this reason, we go to the real value storage place, but the Integertype variable is reference type, which is the address of the object, not the actual value That's why you can have a null.
What is the difference between int vs Integer?
int (Primitive data type (long, float, double, . . .)
Integer (Wrapper class (object)
The difference between storing the actual value or the address value that points to the actual value.
I think it would be easy to understand if you look at the image below. Because it's the same object, it doesn't matter if you view the Employee as an Integer.
Basic type
Reference type
Source of the image . The image was taken from the top answer.
The answer is great, but it is English :D
© 2024 OneMinuteCode. All rights reserved.