Error Compiling Example from Documentation

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Dec 7 04:33:53 PST 2010


On 07/12/10 12:16, Felix Schmidt wrote:
> Everybody,
>
> I tried to compile this example from the documentation:
>
>
> |class Person {
>       private final String name;
>       private final int age;
>
>       public static int compareByAge(Person a, Person b) { return a.name.compareTo(b.name) }
>
>       public static int compareByName(Person a, Person b) { return a - b; }
> }
>
> Person[] people = ... // replaced by something
> Arrays.sort(people, #Person.compareByAge);
>
>
> The javac (lambda included) compiler reports me: lambda/Main.java:[46,29] '{' expected
>
> Is this feature not yet implemented? How could I get this compiled?
>    
The currently implemented syntax for method references is the infix one 
- as such your example should be rewritten as follows:

Person[] people = ... // replaced by something
Arrays.sort(people, Person#compareByAge);


Please refer to the latest syntax tutorial:

http://mail.openjdk.java.net/pipermail/lambda-dev/attachments/20101019/ef738c7f/attachment-0001.txt

Maurizio
> - Felix
>
> |
>
>
>
>    



More information about the lambda-dev mailing list