Predict the output
What does this print?
data class Point(val x: Int, val y: Int)
fun main() {
val a = Point(1, 2)
val b = Point(1, 2)
val c = a
println("${a == b} ${a === b} ${a === c}")
}Hint 1 of 1
Which operator calls equals?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A true false true
Correct. a and b are equal but different objects; c is the same object as a.
Why not the others?
- B true true true. a and b are two separate instances.
- C false false true. Data classes generate equals from properties.
- D true false false. c refers to the same instance as a.