Java8 Lambdas and Exceptions

后端 未结 5 2052
面向向阳花
面向向阳花 2020-11-29 02:16

I wonder if someone could explain the following weirdness to me. I\'m using Java 8 update 11.

Given this method

private  T runFun(Function         


        
5条回答
  •  囚心锁ツ
    2020-11-29 02:37

    If explicitly adding looks ugly then as a workaround you can replace with orElseGet()

    .orElseGet(() -> throw new RunTimeException("foo"));
    

提交回复
热议问题