O'Reilly logo

Kotlin Programming: The Big Nerd Ranch Guide, First Edition by David Greenhalgh, Josh Skeen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required