java - Eclipse and short circuit evaluation -


im trying use short-circuit evaluation simplify writing of check , eclipse calls "the local variable inherit may not have been initialized" in last statment of if clause, using evaluation method correctly ? can ide understand evaluation of statement ?

if ((classname.startswith("svl")) &&                 ((inherit = aast.findfirsttoken(tokentypes.extends_clause)) == null)                 || !(inherit.gettext().equals("servlet******"))) {             log(aast.getlineno(), "error" + tokenident.gettext());         } 

you have got parentheses wrong, that's causing error. simplified, structure of boolean expression is

(a && b) || c 

where in b assign inherit. if fails, (a && b) short-circuited false, b not evaluated, , c needs evaluated find out final result. clearly, inherit may not have been initialized when c evaluated.

depending on after, can swap positions of , b. ensure b evaluated always. alternatively, need may && (b || c). requirements you.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -