String Representation and Objects Equality
Explore how Kotlin’s toString method works, both by default and with data classes. Understand the concept of object equality using the equals method.
We'll cover the following...
Transforming to a string
The default toString
transformation produces a string that starts with the class name, then the @
sign, and then the unsigned hexadecimal representation of the hash code of the object. The purpose of this is to display the class name and to determine whether two strings represent the same object or not.
Press + to interact
class FakeUserRepositoryfun main() {val repository1 = FakeUserRepository()val repository2 = FakeUserRepository()println(repository1) // e.g. FakeUserRepository@6842775dprintln(repository1) // e.g. FakeUserRepository@6842775dprintln(repository2) // e.g. FakeUserRepository@574caa3f}
...