5

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?

1
  • 2
    If Utility.DEBUGis a constant as indicated by your code, the dead code should already be removed by the java compiler. Commented Feb 15, 2018 at 14:57

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

To make that point clear: It's not the JVM, it's the Java compiler eliminating the dead code, before any Android-specific software comes into play.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.