Reflection Bug?


Please have a look at the following program:

open class OpenClass
class FinalClass

class Demo(
    val llo: List<OpenClass>,
    val llf: List<FinalClass>,
    val lmo: MutableList<OpenClass>,
    val lmf: MutableList<FinalClass>,
    var rlo: List<OpenClass>,
    var rlf: List<FinalClass>,
    var rmo: MutableList<OpenClass>,
    var rmf: MutableList<FinalClass>

fun main() { {
        println("${}: ${it.genericType}")

It prints:

llo: java.util.List<OpenClass>
llf: java.util.List<FinalClass>
lmo: java.util.List<OpenClass>
lmf: java.util.List<FinalClass>
rlo: java.util.List<? extends OpenClass>
rlf: java.util.List<FinalClass>
rmo: java.util.List<OpenClass>
rmf: java.util.List<FinalClass>

Why has only property ‘rlo’ a WildcardType?


That’s how Kotlin generates generic types for a more convenient usage from Java. It emulates declaration site variance with the use site variance. See more details about it and how to change that behavior here:


Thanks a lot for the quick explanation.
So it’s obviously not a bug but a feature :slight_smile: