Created
October 15, 2021 11:24
-
-
Save kaspernielsen/4051011928b8038979efa7e2b895668c to your computer and use it in GitHub Desktop.
boolean init on demand.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FooBar { | |
static Boolean tmpVal; | |
public static void main(String[] args) { | |
tmpVal = true; // readFromConfig | |
// Assuming config is initialized before method is called | |
foo(); | |
} | |
public static void foo() { | |
if (Instance.val) { | |
// foo | |
} else { | |
// bar | |
} | |
} | |
private static class Instance { | |
static final boolean val; | |
static { | |
val = requireNonNull(FooBar.tmpVal, "tmpVal must be initialized before first test"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment