我有幾個unchecked警告,我想壓制,但上來看,我仍然看到這條消息:爲什麼選中警告
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
我使用的是以下類型的註釋,並確實的警告信息在IDE源代碼中消失。
@Override @SuppressWarnings("unchecked")
public GroundBase<J> getGround() {
return ground;
}
我將代碼作爲公共API分發,我想知道用戶在使用過程中是否也會看到該消息。
我正在測試我的代碼junit。 我正在使用Java 8和intelliJ 2016.3.6。
我已閱讀-Xlint:unchecked
建議的詳細信息。代碼中沒有更多未註釋的部分,但編譯器建議仍不會消失(或減少)。
編輯
更好地情境我收到警告,在這裏的簡化,但仍然相關,部分代碼之一:
abstract public class MORBase<J extends OWLObject>
implements Descriptor<OWLReferences,J>, MORGround<J>
@Override @SuppressWarnings("unchecked")
public GroundBase<J> getGround() {
return ground;
}
}
interface Ground<O,J>{
Ground<J> getGround();
}
interface Descriptor<O,J> {
<I extends Ground<O,J>> I getGround();
}
這裏關於它的完整信息:
warning: [unchecked] getGround() in MORBase implements <I>getGround() in Descriptor
public GroundBase<J> getGround() {
^
return type requires unchecked conversion from GroundBase<J#1> to I
where J#1,I,O,J#2 are type-variables:
J#1 extends OWLObject declared in class MORBase
I extends Ground<O,J#2> declared in method <I>getGround()
O extends Object declared in interface Descriptor
J#2 extends Object declared in interface Descriptor
我很欣賞界面設計的建議,但我的問題是關於爲什麼警告沒有得到suppres SED。
您是否嘗試使用'-Xlint:unchecked'編譯?也許導致警告的代碼與您壓制的代碼不同。 – Radiodef
爲什麼要壓制這些警告而不是修復它們?您是否在評論這些抑制因素,以及爲什麼他們被認爲是安全的強制轉換,正如在_Effective Java_一書中推薦的那樣?他們實際上是否被認爲是安全的演員?你的例子沒有顯示任何未經檢查的強制轉換,更不用說回答這些問題。 –
我發佈的代碼只是一個例子。我的實際方法使用泛型並且更復雜,但這不是我的問題的主要觀點。 – user2497897