java - Will this if statement throw an exception or ignore it? -
this question has answer here:
- java logical operator short-circuiting 8 answers
will code not evaluate divide 0 portion of if statement since first part evaluates false? if so, true cases in java ides? or compilers throw exception?
int n = 0; int x = 5; if (n != 0 && x / n > 100) { system.out.println(" s1"); } else { system.out.println("s2"); }
from jls §15.23:
the conditional-and operator && & (§15.22.2), evaluates right-hand operand if value of left-hand operand true.
so no, not exception.
obviously assumes have single-threaded or thread safe environment - if introduce visibility problems mix it's anyone's guess.
Comments
Post a Comment