In official Kotlin reference https://kotlinlang.org/docs/reference/basic-types.html#numbers I read that:
Note that boxing of numbers does not necessarily preserve identity
and example which shows how it can be represented:
val a: Int = 10000
print(a === a) // Prints 'true'
val boxedA: Int? = a
val anotherBoxedA: Int? = a
print(boxedA === anotherBoxedA) // !!!Prints 'false'!!!
After some spontaneous testing I realized that it works as should for byte numbers (<128):
val a = 127
val boxedA: Int? = a
val anotherBoxedA: Int? = a
print(boxedA === anotherBoxedA) //!!!Prints 'true'!!!
Also in the same reference https://kotlinlang.org/docs/reference/equality.html I have found that:
For values which are represented as primitive types at runtime (for example, Int), the === equality check is equivalent to the == check
But this doesn't explain this case as for:
val a = 128
val boxedA: Int? = a
val anotherBoxedA: Int? = a
print(boxedA === anotherBoxedA) //!!!Prints 'false'!!!
So I am trying to get a glue why referential equality "===" shows "false" for numbers >=128 and "true" for <128?