Java 8 generics + exceptions compile time error when using a lambda expression

前端 未结 1 1007
栀梦
栀梦 2021-02-15 17:39

A couple of days ago, I started refactoring some code to use the new Java 8 Streams library. Unfortunately, I ran into a compile time error when performing Stream::map with a me

相关标签:
1条回答
  • 2021-02-15 18:12

    A very simple solution is to explicitly provide a type argument for Parameter#execute(..).

    params.stream().map(p -> p.<RuntimeException>execute(foo)); // Gives a compile time error.
    

    Without the explicit type argument, it seems like the JDK compiler cannot infer a type argument from the invocation context, though it should. This a bug and should be reported as such. I have now reported it and will update this question with new details when I have them.

    Bug Report

    0 讨论(0)
提交回复
热议问题