問題描述
任何人都可以清楚地解釋 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')
這篇關于不同的保留政策如何影響我的注釋?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!