java - 不同的保留策略如何影响我的注释?

标签 java annotations

谁能清楚地解释一下java.lang.annotation.RetentionPolicy常量SOURCECLASSRUNTIME之间的实际差异?

我也不太确定“保留注释”这个短语的含义。

最佳答案

  • 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

来源: 旧的 URL 现在已失效 <罢工> hunter_meta 并替换为 hunter-meta-2-098036 。万一出现这种情况,我会上传页面的图像。

<强> Image (右键单击并选择“在新选项卡/窗口中打开图像”) Screenshot of Oracle website

关于java - 不同的保留策略如何影响我的注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48696865/

相关文章:

java - 与 “JAVA exception handling mindset”相比, “C++ exception handling”是什么?

java - super 新手问题 : Getting a returned integer value from a Method

java - JTable 表头格式

java - XML dateTime 解码为 NULL

java.lang.IllegalArgumentException : can't parse argument number: Phone 异常

java - 创建 Java Apache POI 折线图,其中日期显示在水平 X 轴上

java - mongodb日期转换问题

annotations - 拉伸(stretch)组件,而不是连接器

java - 使用反射从界面获取注释

java - 执行上下文 :component-scan programatic way?