Sobes.tech
Junior — Middle

How can you check in Kotlin if two objects are the same instance by reference?

sobes.tech AI

Answer from AI

In Kotlin, to check whether two variables refer to the same object in memory, the === operator is used. It checks referential equality, unlike ==, which checks structural equality (calls equals()).

Example:

val a = Any()
val b = a
val c = Any()

println(a === b) // true, because b refers to the same object
println(a === c) // false, different objects