Why didn't this java 8 example using type inference compile in Eclipse?

前端 未结 1 1261
青春惊慌失措
青春惊慌失措 2020-12-19 04:23

I am reading the newly released Java 8 in Action and found there is a piece of code pasted from Chapter 5 not compiling:

    List numbers1 = A         


        
相关标签:
1条回答
  • 2020-12-19 05:12

    First, correcting your terminology: when you say syntax sugar, what you really are asking about is type inference, that when asked to infer a type for j in the inner lambda, that the compiler fails to come up with the right type.

    Second, correcting your data: The error messages you cite are not coming from the JDK compiler; they're coming from Eclipse.

    This is just an Eclipse bug. The reference compiler (javac from Oracle JDK) handles your first example just fine.

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