Last active
September 16, 2020 19:22
-
-
Save shawnz/5e9a0d344a6a693b46c662c5c8124596 to your computer and use it in GitHub Desktop.
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
import java.io.IOException; | |
import java.sql.SQLException; | |
public class Test { | |
public static String a(String x) throws IOException { | |
return x; | |
} | |
public static String b(String x) throws SQLException { | |
return x; | |
} | |
public static <X, Y, Z, T1 extends Throwable, T2 extends Throwable> FuncThrowingTwoExceptions<X, Z, T1, T2> compose( | |
FuncThrowingOneException<X, Y, T1> a, FuncThrowingOneException<Y, Z, T2> b) { | |
return t -> b.apply(a.apply(t)); | |
} | |
public static String c(String x) throws IOException, SQLException { | |
return compose(Test::a, Test::b).apply(x); | |
} | |
} | |
interface FuncThrowingOneException<X, Y, T extends Throwable> { | |
Y apply(X x) throws T; | |
} | |
interface FuncThrowingTwoExceptions<X, Y, T1 extends Throwable, T2 extends Throwable> { | |
Y apply(X x) throws T1, T2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment