How do different retention policies affect my annotations?(不同的保留政策如何影响我的注释?)
问题描述
任何人都可以清楚地解释 java.lang.annotation.RetentionPolicy 常量
?SOURCE
、CLASS
和 CLASS
之间的实际区别吗?代码>运行时间
我也不确定保留注释"这个短语是什么意思.
RetentionPolicy.SOURCE
:丢弃期间编译.这些注释不编译后有意义已完成,因此它们不会被写入字节码.
示例:@Override
、@SuppressWarnings
RetentionPolicy.CLASS
:丢弃期间类负载.做的时候有用字节码级后处理.有点意外,这是默认.
RetentionPolicy.RUNTIME
:不要丢弃.注释应该是可在运行时进行反射.示例:@Deprecated
来源:旧网址现已失效
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')
这篇关于不同的保留政策如何影响我的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不同的保留政策如何影响我的注释?


基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01