This question already has answers here:
Kotlin boxed Int are not the same

(3个答案)


2年前关闭。




kotlin中,nullable值不保留身份,而是保持相等,
val a: Int = 10000
val boxedA: Int? = a
val anotherBoxedA: Int? = a
print(boxedA === anotherBoxedA) // !!!Prints 'false'!!!
print(boxedA == anotherBoxedA) // Prints 'true'

我只是想知道为什么有什么不同?

最佳答案


boxedA === anotherBoxedA.并非如此

Kotlin - Equality

10-04 22:44