简体   繁体   English

从Method类中获取注释字段

[英]Fetching annotations field from Method class

I'm trying to fetch the annotations field from Method class in Android Sdk 19 and jdk 1.7. 我正在尝试从Android Sdk 19和jdk 1.7中的Method类获取注释字段。 But the code below is throwing NoSuchFieldException. 但是下面的代码抛出NoSuchFieldException。 But I could find the exact field in Method.java file. 但是我可以在Method.java文件中找到确切的字段。

Field field = Method.class.getDeclaredField("annotations");

You can't read the field cause it's private , in order to get around it you have to make it accessible first: 您无法阅读该字段,因为它是private ,要绕过它,您必须首先使其可访问:

    Field f = Method.class.getDeclaredField("annotations"); 
    f.setAccessible(true);
    System.out.println("f = " + f);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM