![](/img/trans.png)
[英]Eclipse IDE dead code warning with two conditions — how to suppress it?
[英]How do I suppress Eclipse 3.5's warnings of dead code
我使用一個類來檢測使用靜態最終布爾值來配置匹配行為的電子郵件地址 。 自從我升級到Eclipse 3.5后,我收到有關死代碼的警告,因為Eclipse注意到無法訪問其中的一個分支:
private static final boolean ALLOW_DOMAIN_LITERALS = false;
private static final String domain = ALLOW_DOMAIN_LITERALS ? rfc2822Domain : rfc1035DomainName;
奇怪的是,它很滿意:
private static final String domain;
static {
if(ALLOW_DOMAIN_LITERALS) {
domain = rfc2822Domain;
} else {
domain= rfc1035DomainName;
}
}
因為它似乎認識到常見的if(DEBUG)
模式,但三元運算符似乎並不重要。
因為我不想太過分叉,只是為了讓Eclipse保持開心,我寧願把@SuppressWarnings
放在頂部,而不是改變代碼。 不幸的是,除了蠻力"all"
之外,我找不到匹配的。 是否只有死代碼檢測的值?
更新 :來自Adam的評論:
在Eclipse 3.6和更新的Eclipse版本中,現在可以使用@SuppressWarnings("unused")
來抑制“死代碼”警告。 請參閱Christopher Stock的回答 。
另請參閱@SuppressWarnings的Eclipse 4.4(Luna)幫助 。
原始答案:
Eclipse 3.5“know”的所有SuppressWarnings值都列在此頁面中 。 似乎沒有用於僅抑制新的死碼檢測的價值。 但是您可以在domain
聲明之前使用@SuppressWarnings("all")
,因此它將僅針對整個類禁止該行的警告:
private static final boolean ALLOW_DOMAIN_LITERALS = false;
@SuppressWarnings("all")
private static final String domain = ALLOW_DOMAIN_LITERALS ? rfc2822Domain : rfc1035DomainName;
由於死代碼檢查是一個新的,您還可以建議在Eclipse錯誤數據庫中增強以支持三元操作。
在“ Potential programming problems
部分的“ Windows -> Preferences > Java > Compiler > Errors/Warnings
選擇“ Ignore
Windows -> Preferences > Java > Compiler > Errors/Warnings
您可以使用禁用“死代碼”警告
@SuppressWarnings( "unused" )
有關更多信息,請參閱eclipse文檔:
“unused”用於禁止相對於未使用的代碼和死代碼的警告
問候
克里斯托弗
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.