用于自动捕获(隐藏)检查异常,将检查异常包装为运行时异常,在编码时就无需处理该异常了。

    例如:

    1. public class test implements Runnable {
    2. @SneakyThrows(UnsupportedEncodingException.class)
    3. public String utf8ToString(byte[] bytes) {
    4. return new String(bytes, "UTF-8");
    5. }
    6. }

    以上代码等同于:

    1. public class test implements Runnable {
    2. public String utf8ToString(byte[] bytes) {
    3. try {
    4. return new String(bytes, "UTF-8");
    5. } catch (UnsupportedEncodingException e) {
    6. throw Lombok.sneakyThrow(e);
    7. }
    8. }
    9. }