Created
November 18, 2020 18:12
-
-
Save keeferrourke/5b7c9b0946cd418b90de09b0a1842b8d to your computer and use it in GitHub Desktop.
Simple Java implementation of some patterns I really enjoy from Kotlin.
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
class JavaUtil { | |
/** | |
* Runtime checks, similar to the Kotlin standard library check method. | |
*/ | |
public static void check(boolean condition, String message) { | |
if (!condition) { | |
throw new IllegalStateException(message); | |
} | |
} | |
public static void check(boolean condition) { | |
check(condition, "check failed"); | |
} | |
/** | |
* Silence annoying IDE errors when drafting methods, similar to the Kotlin | |
* standard library method. | |
* For method stubs, simply `return TODO("Not implemented");`. | |
*/ | |
@SuppressWarnings("UnusedReturnValue") | |
public static <T> T TODO(String message) { | |
throw new IllegalStateException(message); | |
} | |
public static <T> T TODO() { | |
throw new IllegalStateException("TODO"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment