我有一个科特林类,其性质有一个Java注释,但我不能接取这些注解与Java反射:如何从Java中获取Kotlin属性的注释?
class TestClass(@A var myProperty : String)
下面的测试打印空:
public class TestKotlinField {
@Retention(RetentionPolicy.RUNTIME)
public @interface A{}
@Test
public void test() throws NoSuchFieldException {
System.out.println(TestClass.class.getDeclaredField("myProperty").getAnnotation(A.class));
}
}
我怎样才能得到给定kotlin属性的注释?
这是一个参数,而不是属性。 – shmosel
@VinceEmigh我不熟悉Kotlin,但我会怀疑这个注解适用于构造函数参数而不是隐式属性。 – shmosel
@VinceEmigh很好。我将停止进一步炫耀自己的无知。 – shmosel