如何不同的保留策略影响我的注解? [英] How do different retention policies affect my annotations?

查看:174
本文介绍了如何不同的保留策略影响我的注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以明确的方式任何人都可以解释 java.lang.annotation.RetentionPolicy 常数之间的实际差别来源运行

我也不太确定是什么那句保持注释的意思。


解决方案

  

      
  • RetentionPolicy.SOURCE :在放弃
      编译。这些注释不
      任何意义编译后有
      完成的,所以它们不会被写入
      字节code。结果
      例如: @覆盖 @燮pressWarnings


  •   
  • RetentionPolicy.CLASS :在放弃
      类加载。当这样做有用
      字节code级后处理。
      出人意料的是,这是
      默认值。


  •   
  • RetentionPolicy.RUNTIME :不
      丢弃。注释应该是
      可在运行时反射。
      例如: @ pcated德$ P $


  •   

来源:
旧的URL,现在已经死了
<击> hunter_meta 和<一个取代href=\"http://www.oracle.com/technetwork/articles/hunter-meta-2-098036.html\">hunter-meta-2-098036.万一即使此下降,我上传页的图像。

图片(点击右键,在新标签/窗口打开图片选择)

Can anyone explain in a clear way the practical differences between the java.lang.annotation.RetentionPolicy constants SOURCE, CLASS, and RUNTIME?

I'm also not exactly sure what the phrase "retaining annotation" means.

解决方案

  • RetentionPolicy.SOURCE: Discard during the compile. These annotations don't make any sense after the compile has completed, so they aren't written to the bytecode.
    Example: @Override, @SuppressWarnings

  • RetentionPolicy.CLASS: Discard during class load. Useful when doing bytecode-level post-processing. Somewhat surprisingly, this is the default.

  • RetentionPolicy.RUNTIME: Do not discard. The annotation should be available for reflection at runtime. Example: @Deprecated

Source: The old URL is dead now hunter_meta and replaced with hunter-meta-2-098036. In case even this goes down, I am uploading the image of the page.

Image (Right Click and Select 'Open Image in New Tab/Window')

这篇关于如何不同的保留策略影响我的注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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