The Kotlin Type Hierarchy

If you do not specify a class to extend from, your class implicitly descends from a common superclass called Any. This means that every type in the language eventually extends from Any. In the case of your TownSquare class, the class hierarchy looks like Figure 15.2:

Figure 15.2  TownSquare type hierarchy

TownSquare type hierarchy

You can also use Any to define functions that accept any type of argument. Suppose that in NyetHack there are two things that can be a source of blessings: a blessed player or the room called The Fount of Blessings. A printIsSourceOfBlessings function, which checks and prints whether an object ...

Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.