There is no C-like conditional compilation in Java unless you implement it yourself. (Itβs not all that complicated, but IMO itβs not worth the problem.)
Your options are pretty limited. The best you can do is wrap the expensive logging statements in isLoggable .
if (Log.isLoggable(tag, Log.DEBUG)) { Log.d(tag, expensiveStringGeneration()); }
For short magazine operators, this is more noise than it costs.
Editing Malcolm may be correct (although I still won't worry, in all likelihood.)
Edit Comparison with static DEBUG is still in byte code; ProGuard should delete an unnecessary branch. Without ProGuard, this will be before the JIT or compiler implementation.
Dave newton
source share