Will the optimizer prevent the creation of a string parameter if a constant will prevent it from being used? <p>My question is best made with an example.</p> <pre><code> public static boolean DEBUG = false; public void debugLog(String tag, String message) { if (DEBUG) Log.d(tag, message); } public void randomMethod() { debugLog("tag string", "message string"); //Example A debugLog("tag string", Integer.toString(1));//Example B debugLog("tag string", generateString());//Example C } public String generateString() { return "this string"; } </code></pre> <p>My question is, in any of the examples, A, B or C - since the string would not be used ultimately would the optimizer remove it?</p> <p>Or asked another way, would it be better to do the following, thus ensuring that the string objects would not be created?</p> <pre><code> public void randomMethod() { if (DEBUG) debugLog("tag string", "message string"); //Example A if (DEBUG) debugLog("tag string", Integer.toString(1));//Example B if (DEBUG) debugLog("tag string", generateString());//Example C } </code></pre>