You can pass custom values โโon the command line and then check that value once. So there is something like this in your code:
final static boolean customProp = "true".equalsIgnoreCase(System.getProperty("customProp"));
Depending on the command line options, the static final value will change. This will set to true :
java -DcustomProp="true" -jar app.jar
So far, this value will be set to false :
java -jar app.jar
This gives you the benefits of static final boolean , but allows you to change the value without recompiling.
[change]
As pointed out in the comments, this approach does not optimize compilation time. The static final boolean value is set on class loading and does not change from there. The "normal" byte code execution will probably need to be evaluated by each if (customProp) . However, JIT occurs at runtime by compiling the bytecode to its own code. At this point, since the bytecode has a run-time value, more aggressive optimizations are possible, such as embedding or excluding code. Please note that you cannot accurately predict whether or not there will be JIT.
source share