小编Jay*_*ser的帖子

如何在 Kotlin 中检查类属性是否为 List 类型

如何检查类的属性是否为列表类型?下面的代码片段是我想要的,但它不起作用。

class MyClass(val attr:List<String>)
fun main(args: Array<String>) {
    var prop = MyClass::attr
    if(prop.returnType.classifier is List<*>)
        println("Property is type of List")
}
Run Code Online (Sandbox Code Playgroud)

reflection typeof kotlin

2
推荐指数
1
解决办法
1710
查看次数

标签 统计

kotlin ×1

reflection ×1

typeof ×1