Java lambda returning a lambda

前端 未结 4 867
借酒劲吻你
借酒劲吻你 2020-11-27 06:01

I am trying to do what seems to be a relatively basic thing in the new JDK 8 land of functional programming, but I can\'t get it to work. I have this working code:

4条回答
  •  青春惊慌失措
    2020-11-27 06:30

    I haven't yet delved into the exact rules for how type inference works with lambdas. From a general language design standpoint, though, it isn't always possible to write language rules that allow the compiler to figure out everything we think it should. I've been a compiler maintainer for an Ada-language compiler and I'm familiar with many of the language design issues there. Ada uses type inference in a lot of cases (where the type of a construct can't be determined without looking at the entire expression containing the construct, which I think is the case with this Java lambda expression also). There are some language rules that cause compilers to reject some expressions as ambiguous when, in theory, there really is only one possible interpretation. One reason, if I recall correctly, is that somebody found a case where a rule that would have let the compiler figure out the correct interpretation would have required the compiler to make 17 passes through an expression in order to interpret it correctly.

    So while we may think a compiler "should" be able to figure something out in a particular case, it may just plain be unfeasible.

提交回复
热议问题