Skip to content

Instantly share code, notes, and snippets.

@keeferrourke
Created November 18, 2020 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keeferrourke/5b7c9b0946cd418b90de09b0a1842b8d to your computer and use it in GitHub Desktop.
Save keeferrourke/5b7c9b0946cd418b90de09b0a1842b8d to your computer and use it in GitHub Desktop.
Simple Java implementation of some patterns I really enjoy from Kotlin.
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