I know how to create a reference to a method that has a String
parameter and returns an int
, it\'s:
Function
By default, Java 8 Function does not allow to throw exception and as suggested in multiple answers there are many ways to achieve it, one way is:
@FunctionalInterface
public interface FunctionWithException {
R apply(T t) throws E;
}
Define as:
private FunctionWithException myMethod = (str) -> {
if ("abc".equals(str)) {
throw new IOException();
}
return 1;
};
And add throws
or try/catch
the same exception in caller method.