Java / Android code optimization: does Java eliminate unreachable code during assembly

Please take a look at this sample android code:

private static final boolean aBoolean = false; ... if(aBoolean){ //do something like logs } 

In this case, since the value of aBoolean is false and that it cannot change at run time, will // do something like a logs report when building, or will it still be collected and will evaluate if each time?

I am trying to find behavior like pre processor #DEFINE #IF ... so that when I code, I get my logs when I free, I switch one value and all my debug code is completely ignored.

(I would also like to point out that my question is focused on android, so if there is a difference between Java and Android on this, please let me know)

+6
java optimization android
source share
2 answers

Checking the variable for logging is excellent. Even if the code is not optimized, checking the Boolean condition almost does not work, and you optimize very early.

But to answer your question, it is likely to be optimized.

+3
source share

if the statement is unreachable, it will always give a compile-time error .....

eg. if you use return statemnt b4 any code this will give a compile-time error.

but if you use this type of code

if (aBoolean) {// do something}

this does not avoid java or delete byjava ........

-2
source share

All Articles