Type erasure

Kotlin is designed primarily as a language for the Java Virtual Machine (JVM), and when the JVM was first designed, generics were not included as a feature. Over time it became apparent that this was a major flaw of the language, and so in Java 1.5 (or Java SDK 5), released in 2004, generics were added as a feature to the compiler.

However, because of a desire to stay backwards compatible with previous versions of Java, the designers of Java decided that generics would be implemented using a technique called erasure. Erasure is the name given to the process by which the compiler removes type parameters during compilation.

In Java, a class defined as List<T> in the source code would be compiled simply as List, or List<Object>, if you ...

Get Programming Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.