...

/

Any and Nothing Classes

Any and Nothing Classes

We'll cover the following...

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 ubiquitous Any and the purpose of Nothing.

Any, the base class

...