The Kotlin Type Hierarchy

Every class in Kotlin descends from a common superclass, known as Any, without you having to explicitly subclass it in your code (Figure 14.2).

Figure 14.2  TownSquare type hierarchy

TownSquare type hierarchy

For example, a Room and a Player are both implicitly children of Any, which is why you can define functions that will accept either of them as parameters. If you have worked with Java, this is similar to how classes in Java subclass the java.lang.Object class implicitly.

Consider the following example of a function called printIsSourceOfBlessings. printIsSourceOfBlessings takes in an argument of type Any and uses ...

Get Kotlin Programming: The Big Nerd Ranch Guide, First 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.