Inheritance

Android loves inheritance. We can see this affection in Activity, Fragments, Services, Receivers, and the Application class. EVERYWHERE !! And inspired by this we also do it in multiple places. But here comes the twist. In Kotlin all classes are final by default. So if you want some class to be open for the extension you have to use the open keyword.

The open annotation on a class is the opposite of Java's final, that is, it allows others to inherit from this class. By default, all classes in Kotlin are final, which corresponds to Effective Java, Item 17: Design and document for inheritance or else prohibit it (https://books.google.fr/books?id=ka2VUBqHiWkC&lpg=PA87&ots=yZKjLhuZRY&pg=PA87#v=onepage&q&f=false).

An open class and ...

Get Kotlin Blueprints 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.