Skip to content

Instantly share code, notes, and snippets.

@rzwitserloot
Created February 6, 2020 22:00
Show Gist options
  • Save rzwitserloot/c747b45c33d1055d4fbfe64a450c897a to your computer and use it in GitHub Desktop.
Save rzwitserloot/c747b45c33d1055d4fbfe64a450c897a to your computer and use it in GitHub Desktop.
@FunctionalInterface interface BetterRunnable<E extends Throwable> {
void run() throws E;
}
public class BetterLambdaThrow {
static <E extends Throwable> void runTwice(BetterRunnable<E> r) throws E {
r.run();
r.run();
}
public static void main(String[] args) {
runTwice(() -> System.out.println("Hello, World!"));
try {
runTwice(() -> {throw new java.io.IOException();});
} catch (java.io.IOException e) {
System.out.println("caught");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment