谁能清楚地解释java.lang.annotation.RetentionPolicy
常量SOURCE
、CLASS
和运行时间
?
我也不确定“保留注释”这个短语是什么意思。
最佳答案
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
来源: 旧网址现已失效 <罢工> hunter_meta 并替换为 hunter-meta-2-098036 .万一出现这种情况,我正在上传页面的图像。
Image (右键单击并选择“在新选项卡/窗口中打开图像”)
关于java - 不同的保留政策如何影响我的注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3107970/