你需要执行以下操作之一。
如果是你的代码,请定义自己的函数接口,该接口声明已检查的异常:
@FunctionalInterfacepublic interface CheckedFunction<T, R> { R apply(T t) throws IOException;}并使用它:
void foo (CheckedFunction f) { ... }否则,包装
Integer myMethod(String s)一个不声明检查异常的方法:
public Integer myWrappedMethod(String s) { try { return myMethod(s); } catch(IOException e) { throw new UncheckedIOException(e); }}接着:
Function<String, Integer> f = (String t) -> myWrappedMethod(t);
要么:
Function<String, Integer> f = (String t) -> { try {return myMethod(t); } catch(IOException e) { throw new UncheckedIOException(e); } };


