java - Does order of compared literals matter if both are evaluated? -
this question has answer here:
i have rather stupid question. point is, see if
statement looking this:
private int smth; // ... if (3 == smth) // ...
the order feels odd me. think decreases readability of code.
is there profit putting literals compared each other binary operator in order within if
statement?
is there profit putting literals compared each other binary operator in order within if statement?
not in java, unless booleans:
if (false == flag)
in one case, helps avoid typo:
if (flag = false)
...which compiler won't protect (that assign false
flag
, never evaluate true).
in other cases (anything isn't boolean
), java compiler won't let make mistake. , of course, when testing booleans, it's best test boolean:
if (!flag)
or
if (flag)
depending on value you're looking for.
Comments
Post a Comment