谁能清楚地解释一下java.lang.annotation.RetentionPolicy
常量SOURCE
、CLASS
和RUNTIME
之间的实际差异?
我也不太确定“保留注释”这个短语的含义。
最佳答案
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 (右键单击并选择“在新选项卡/窗口中打开图像”)
关于java - 不同的保留策略如何影响我的注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48696865/