Hi, is there any reason it is allowed to create a KClass for Array with variance? I mean something like this:
Array<out Animal>::class
The problem here is that because KClass
/Class
can’t hold information about the variance, this information is lost and then the reflection behaves in an inconsistent way. See this example:
val intArray = arrayOf(1, 2, 3)
// Upcasted imlicitly as Array<Int> is a subtype of Array<out Any?>
val arr: Array<out Any?> = intArray
// false, because information about the variance is silently ignored
println(Array<Int>::class.isSubclassOf(Array<out Any?>::class))
Shouldn’t Array<out Animal>::class
be disallowed, similarly to e.g. List<String>::class
?