I have code like this:
MyLog.d("TAG", "debug string " + aVariable + " more debug string =" + anotherVariable);
And MyLog class is like
public void d(String tag, String message) {
private static final boolean DEBUG = true;
if (DEBUG) {
Log.d(tag, message);
}
}
My question is if I set DEBUG to false, will android java compiler smartly detect that this line of code
MyLog.d("TAG", "debug string " + aVariable + " more debug string =" + anotherVariable);
does nothing
and it won't create temporary string objects for "debug string " + aVariable + " more debug string =" + anotherVariable
You're doing the string concatenation before anything related to the DEBUG matters: I doubt that would be optimized out by ProGuard, although the call to Log.d inside MyLog.d would disappear.
If you check the bytecode, it'd be worth reporting back; I'm curious how far ProGuard will follow a call chain to detect dead code. I'd be surprised if the string concatenation went away.
You also can't declare a variable private like that inside a method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With