Operators: Equality, Inequality, and Comparison
Explore how Kotlin implements equality and inequality with structural and referential checks, and understand how comparison operators enhance readability through operator overloading for natural object ordering.
We'll cover the following...
We'll cover the following...
The equality and inequality operators
In Kotlin, there are two types of equality:
Structural equality: It is checked with the
equalsmethod or the==operator (and its negated counterpart!=).The statemenet
a == btranslates toa.equals(b)whenais not nullable. Otherwise, ...