1

As per the official documentation KotlinLang, Nullable number reference (e.g. Int?) are boxed.

boxedA === anotherBoxedA evaluates to true if and only if boxedA and anotherBoxedA point to the same object

val a: Int = 10000
println(a === a) // Prints 'true'
val boxedA: Int? = a
val anotherBoxedA: Int? = a
println(boxedA === anotherBoxedA) // !!!Prints 'false'!!!

But if I just change the value of a to 80, the Referential equality becomes true!!

val a: Int = 80
println(a === a) // Prints 'true'
val boxedA: Int? = a
val anotherBoxedA: Int? = a
println(boxedA === anotherBoxedA) // !!!Prints 'true'!!!

How can it point differently just by the change of value?

RöHIT
  • 29
  • 7

0 Answers0