JavaAndroid

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:

But be aware, most of the time, when it warns you, you should follow the editor's advice rather than add @SuppressWarnings.
上一篇下一篇

猜你喜欢

热点阅读