So if code:
if(f() && false) {
// never happens
}
Can i be always sure that f() will be called and will be never ‘optimised-away’ by compiler?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
javaccompiler does very little optimisation.The JIT can optimise code away but in this case you can be sure that
&&and||are always evaluated left to right.http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
From the JLS.
http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html