– code –
class Car(val color: String)– code –
fun main() {
val car1 = Car(“red”)
val car2 = Car(“blue”)
val car3 = Car(“red”)
if (car1 == car2) {
println(“car1-car2: same”)
} else {
println(“car1-car2: different”)
}
if (car1 == car3) {
println(“car1-car3: same”)
} else {
println(“car1-car3: different”)
}
val x: Int = 100
val y: Int = 100
if (x == y) {
println(“x-y: same”)
} else {
println(“x-y: different”)
}
if (x === y) {
println(“x-y: same”)
} else {
println(“x-y: different”)
}
}
/*
car1-car2: different
car1-car3: different
x-y: same
x-y: same
Process finished with exit code 0
*/
I expected ‘car1-car3: same’.
I thought car1 and car3 are the same as structurally.