Java suppress warning
2019-02-18 本文已影响0人
JaedenKil
Sometimes Java editor warns you something, but you're pretty sure that is exactly what you want.
try {
UiObject2 systemScoreObj = systemParent.getChildren().get(1);
return false;
} catch (java.lang.IndexOutOfBoundsException ex) {
return true;
}
I simply want to return "true" or "false", don't care about the "UiObject2", so add suppress warning to the method.
@SuppressWarnings("unused")
private boolean blankResult(int round) throws IOException {
...
UiObject2 systemParent = system.getParent();
try {
UiObject2 systemScoreObj = systemParent.getChildren().get(1);
return false;
} catch (java.lang.IndexOutOfBoundsException ex) {
return true;
}
}
Typically we can type javac -X
to get a list of useful suppress warning messages:
> javac -X
-Xlint Enable recommended warnings
-Xlint:{all,auxiliaryclass,cast,classfile,deprecation,dep-ann,divzero,empty,fallthrough,finally,options,overloads,overrides,path,processing,rawtypes,serial,static,try,unchecked,varargs,-auxiliaryclass,-cast,-classfile,-deprecation,-dep-ann,-divzero,-empty,-fallthrough,-finally,-options,-overloads,-overrides,-path,-processing,-rawtypes,-serial,-static,-try,-unchecked,-varargs,none} Enable or disable specific warnings
But there are some special suppress warning messages:
- @SuppressWarnings("FieldCanBeLocal")
Original warning: Field can be converted to a local variable - @SuppressWarnings("unused")
Original warning: Variable xx is never used - @SuppressWarnings("unchecked")
Original warning: Unchecked call ... or Unchecked assignment... - @SuppressWarnings("SameParameterValue")
Original warning: Actual value of parameter xx is always yy - @SuppressWarnings("unused")
Original warning: Parameter xx is never used - @SuppressWarnings({"unused", "SameParameterValue"})
Combination of the two above