用于自动捕获(隐藏)检查异常,将检查异常包装为运行时异常,在编码时就无需处理该异常了。
例如:
public class test implements Runnable {
@SneakyThrows(UnsupportedEncodingException.class)
public String utf8ToString(byte[] bytes) {
return new String(bytes, "UTF-8");
}
}
以上代码等同于:
public class test implements Runnable {
public String utf8ToString(byte[] bytes) {
try {
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw Lombok.sneakyThrow(e);
}
}
}