相关疑难解决方法(0)

Kotlin - 如何获取注释属性值

比方说,我有一个带注释的Kotlin类:

@Entity @Table(name="user") data class User (val id:Long, val name:String)
Run Code Online (Sandbox Code Playgroud)

如何从@Table注释中获取name属性的值?

fun <T> tableName(c: KClass<T>):String {
    // i can get the @Table annotation like this:
    val t = c.annotations.find { it.annotationClass == Table::class }
    // but how can i get the value of "name" attribute from t?
}
Run Code Online (Sandbox Code Playgroud)

annotations kotlin

9
推荐指数
1
解决办法
6310
查看次数

标签 统计

annotations ×1

kotlin ×1