Java 8 Lambda function that throws exception?

后端 未结 26 1729
臣服心动
臣服心动 2020-11-22 03:14

I know how to create a reference to a method that has a String parameter and returns an int, it\'s:

Function         


        
26条回答
  •  不知归路
    2020-11-22 03:35

    If you have lombok, you can annotate your method with @SneakyThrows

    SneakyThrow does not silently swallow, wrap into RuntimeException, or otherwise modify any exceptions of the listed checked exception types. The JVM does not check for the consistency of the checked exception system; javac does, and this annotation lets you opt out of its mechanism.

    https://projectlombok.org/features/SneakyThrows

提交回复
热议问题