Please help me understand this piece of code in the kotlin docs:-
val a: Int = 10000
print(a === a) // Prints 'true'
val boxedA: Int? = a
val anotherBoxedA: Int? = a
print(boxedA === anotherBoxedA) // !!!Prints 'false'!!!
Now, I understand that first int a = 10000
then in the next line it is comparing it using ===
.
Now the question is why when it assigned boxedA=a
, it checked if it is null using int?
. Can it just be written like this:-
val boxedA: Int=a
Please if I'm understanding it the wrong way, someone guide to check the right place or explain it a bit for me.
Int
is the same as Javasint
(a primitive) whileInt?
is the same asInteger
(an object) – MuimuirInt
maps toint
andInt?
toInteger
. Or do you mean because of the caching range? – Muimuir