Skip to content

Instantly share code, notes, and snippets.

@keeferrourke
Created November 18, 2020 18:12
Show Gist options
  • Select an option

  • Save keeferrourke/5b7c9b0946cd418b90de09b0a1842b8d to your computer and use it in GitHub Desktop.

Select an option

Save keeferrourke/5b7c9b0946cd418b90de09b0a1842b8d to your computer and use it in GitHub Desktop.

Revisions

  1. keeferrourke created this gist Nov 18, 2020.
    28 changes: 28 additions & 0 deletions JavaUtil.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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");
    }
    }