Equality comparison

If you are familiar with Java, then you know that the == operator on reference types is used for comparing reference (memory address) equality. If you want to compare structural equality, you should call the equals method from the base Object class.

Kotlin overrides the == operator so that it calls the equals method, that is, it is used for structural comparison. If you want to compare two objects for reference equality in Kotlin, then you can use the three equals signs, the === operator and !== for a negation of reference equality:

val a = "Kotlin"
val b = "Kotlin"
val c = "Java"
println("Strings a and b are equal in content: ${a == b}")
println("Strings b and c are equal in reference: ${b === c}")
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.102.166