获取可空类型的类

时间:2018-09-25 01:01:58

标签: reflection kotlin kotlin-reflect

我正在尝试在Kotlin反射练习中匹配可为空的String?的类型:

data class Test(a: String, b: String?)
val test = Test("1", "2")
val properties = test::class.declaredMemberProperties
val propertyNames = properties.joinToString(",") { 
        when (it.returnType) {
            String?::class.createType() -> "string?"
            String::class.createType() -> "string"
            else -> throw Exception()
        }
}

A,它因Type in a class literal must not be nullable的错误String?::class而失败。

1 个答案:

答案 0 :(得分:3)

select datename(month,'2018' + right(fiscal_period,2) + '01') 函数具有一个可选的可为空的参数,该参数在我测试时似乎可以正常工作。

createType
相关问题