Kotlin反射无法访问使用网站的目标注释
我使用注释网站目标@get
困惑了我一会儿。
class GetSiteTarget1(@get:Annotation val value: Int = 1); class GetSiteTarget2 { val value = 1 @Annotation get () { return field; } };
上面两个类都有不同的结果:
GetSiteTarget1::value.getter.annotations; // not has @Annotation GetSiteTarget1::value.getter.javaMethod!!.annotations // has @Annotation GetSiteTarget2::value.getter.annotations; // has @Annotation GetSiteTarget2::value.getter.javaMethod!!.annotations // has @Annotation
而且这两个类都用@Annotation
注解:
RuntimeVisibleAnnotations: 0: #10() // @Annotation
谁能告诉我为什么?
但是,使用网站的目标注释在kotlin-reflect中是不可见的。 这是一个已知的问题: https : //youtrack.jetbrains.com/issue/KT-10837 。