Because of type erasure, incomplete type information is available at runtime. For example, type parameters of generic types are not available:
val list = listOf(1,2,3) println(list.javaClass) // Prints: class java.util.Arrays$ArrayList
This leads to a few problems. We can't perform any checks to verify what types of element List
contains:
/* Compile time error: cannot check instance of erased type: List<String> */ if(collection is List<Int>) { //... }
The problem occurs because a check is performed at runtime where information about type parameters is not available. Kotlin, however, as opposed to Java, does not allow us to declare a raw type (a generic type that is not parametrized with a type argument):
SimpleList<> // Java: ok SimpleList<> // Kotlin: error
Kotlin allows us to use star-projection syntax instead, which is basically a way to say that information about the type argument is missing or it is...