lambda: catch exception by SAM method substitution (IDEA-116441)

(cherry picked from commit 0bce39590bdcc6e6a74c0dcedbb02add3333e685)
This commit is contained in:
anna
2013-11-15 17:11:10 +01:00
parent 79c9afb33c
commit f7fd8525b9
3 changed files with 43 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
import java.io.IOException;
class Main48 {
public static void main(String[] args) throws Exception {
templateMethod(( ) -> {
throw new IOException();
});
}
static void templateMethod(RunnableWithException<IOException> r) {
try {
r.run();
} catch (IOException e) {
e.printStackTrace();
}
}
interface RunnableWithException<E extends Exception> {
void run() throws E;
}
}