#ifdef #ifndef in Java

private static final boolean enableFast = false;

// ...
if (enableFast) {
  // This is removed at compile time
}

Conditionals like that shown above are evaluated at compile time. If instead you use this

private static final boolean enableFast = "true".equals(System.getProperty("fast"));

Then any conditions dependent on enableFast will be evaluated by the JIT compiler. The overhead for this is negligible.

Leave a Comment