我有一个kotlin类,其属性具有Java注释,但我无法使用Java反射访问这些注释:
class TestClass(@A var myProperty : String)
Run Code Online (Sandbox Code Playgroud)
以下测试打印为null:
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));
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得给定kotlin属性的注释?