Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are hardcoded conditions optimized by JVM in Android?

Due to debugging reason most parts of the code in my application has this recurrent portion of code:

public static final boolean DEBUG = true; // just created once in a "Utility" class

  if (Utility.DEBUG)
     Log.d("TIMER", /*string message that is strictly related to context*/);

Now, if the boolean values turn to false this becomes dead code. My question is if in this case the Android compiler would do basics optimizations such as constant folding and dead code remotion?

If the answer is no, what is the best way to whip out in release phase the debugging logs?

like image 957
Thecave3 Avatar asked Feb 15 '18 14:02

Thecave3


1 Answers

Yes; in the case of static final fields the compiler can and will remove the unreachable section. If you examine the byte-code you can validate this yourself.

like image 72
Elliott Frisch Avatar answered Oct 18 '22 02:10

Elliott Frisch