Canonical methods are the methods declared in Any. Therefore, all instances in Kotlin have them.
For data classes, Kotlin creates correct implementations of all canonical methods.
The methods are as follows:
- equals(other: Any?): Boolean: This method compares value equivalence, rather than reference.
- hashCode(): Int: A hash code is a numerical representation of an instance. When hashCode() is invoked several times in the same instance, it should always return the same value. Two instances that return true when they are compared with equals must have the same hashCode().
- toString(): String: A String representation of an instance. This method will be invoked when an instance is concatenated to a String.