自定义函数式接口
/**
* @author congyiqun
* @since 2021-11-10
*/
public interface CheckedRunner {
/**
* 执行一段代码
* @throws Exception
*/
void run() throws Exception;
/**
* 将CheckedException转换成RunTimeException
* @param cf
* @throws RuntimeException
*/
static void wrap(CheckedRunner cf) throws RuntimeException {
try {
cf.run();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
伪代码示例
list.foreach(e -> CheckedRunner.wrap(() -> 声明受检异常));
网友评论