6. Final classes by default

Item 17 in “Effective Java” suggests that every class should either not be sub-classable or be carefully designed and documented to support inheritance. In Java, every class can be subclassed unless you explicitly specify the class as final . If you forget to make the class final and fail to design and document it for inheritance, there will be trouble when clients think that they can create subclasses, override some methods and assume that everything will still work as expected.

In Kotlin, every class is final by default. You must explicitly use the keyword open , which is the exact opposite of Java’s final , to allow the class to be capable of inheritance. This prevents the creation of non-final classes that are not consciously designed for inheritance.

Not everyone in the Kotlin community is happy about the “final by default” design choice. There is an ongoing discussion in the Kotlin forum about this controversal topic.