Any and Nothing Classes
Some methods like equals() and toString() are pervasive. In Java you’d expect to find them in the Object base class. In Kotlin, these methods are included in the Any class, along with a number of other methods that are useful on instances of any class. Any is Kotlin’s counterpart of Java’s Object class, except Any has a lot of special methods that come in through extension functions. Kotlin also has a class named Nothing that serves to stand in as type when a function literally is expected to return nothing—this is useful for type-checking methods when one or more branches is expected to return nothing. Nothing in Java is equivalent to Kotlin’s Nothing. In this section you’ll learn about the facilities offered by the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access