Java注解 - 寻找RetentionPolicy.CLASS的例子 [英] Java Annotations - looking for an example of RetentionPolicy.CLASS

查看:952
本文介绍了Java注解 - 寻找RetentionPolicy.CLASS的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Java注解的API:

according to Java Annotation API:


      
  • RetentionPolicy.CLASS
            注解是由记录在类文件中
      编译器,但不必由被保留
      虚拟机在运行时。

  • RetentionPolicy.CLASS Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.

RetentionPolicy.RUNTIME
        注解是由记录在类文件中
  编译器和运行的VM保留
  时间,因此它们可以被读
  沉思。

RetentionPolicy.RUNTIME Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.

我要寻找CLASS保留策略的样本。当我们需要使用这个策略,而不是运行时策略的。

I am looking for a sample of "CLASS" retention policy. when we need to use this policy instead of RUNTIME policy.

推荐答案

所有的大量我在我的当前项目库的。唯一的例子我能看到的是在谷歌番石榴的库,例如<一个href=\"http://guava-libraries.google$c$c.com/svn/trunk/javadoc/com/google/common/annotations/GwtCompatible.html\"><$c$c>com.google.common.annotations.GwtCompatible.

Of all of the large number of libraries I have in my current project. the only examples I can find are in the Google Guava library, for example com.google.common.annotations.GwtCompatible.

我真的不知道他们为什么选择这个保留策略,虽然 - 也许对工具的支持,其中的工具阅读类文件本身,而不是通过反射API去。我不知道,我真的看到这种区别的角度来看,虽然。

I'm not really sure why they chose this retention policy, though - perhaps for tools support, where the tools read the class files themselves, rather than going through the reflection API. I'm not sure that I really see the point of this distinction, though.

这篇关于Java注解 - 寻找RetentionPolicy.CLASS的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆