Java Compiler: Optimization of "cascaded" ifs and best practices?
- by jens
Hello,
does the Java Compiler optimize a statement like this
if (a == true) {
if (b == true) {
if (c == true) {
if(d == true) {
//code to process stands here
}
}
}
}
to
if (a == true && b==true && c==true && d == true)
So thats my first question: Do both take exactly the same "CPU Cycles" or is the first variant "slowlier".
My Second questin is, is the first variant with the cascaded if considered bad programming style as it is so verbose?
(I like the first variant as I can better logically group my expressions and better comment them (my if statements are more complex than in the example), but maybe thats bad proramming style?) and even slowlier, thats why I am asking...
Thanks
Jens