Method References

Håkon Sandsmark hsandsmark at gmail.com
Mon Jan 24 15:05:58 PST 2011


Hi Markus,

The infix syntax is correct, but you get the compiler error because
you need the parameter '-Dimport.jdk=<PATH-TO-JDK7-BINARIES>' when
building the JDK [1].


Best regards,

Håkon Sandsmark


[1] http://mail.openjdk.java.net/pipermail/lambda-dev/2011-January/002907.html

2011/1/24 Markus Hauschild <hauschil at fim.uni-passau.de>:
> Hi,
>
> as preperation for a talk on Java 7/8 I was trying out several lambda
> feature, however I can't get method references to work:
>
> I am trying to use the method foo from class Test:
>> class Test {
>>   public static void foo() {
>>   System.out.println("Lambda method extraction test 1.");
>> }
>
> By either trying this syntax:
>> Thread t = new Thread(#Test.foo);
>> t.run();
>
> or this:
>> Thread t = new Thread(Test#foo);
>> t.run();
>
> As seen on the Method References chapter of
> http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-3.html
>
>
> But the first one results in:
>> markus at ares ~/workspace/jdk7-lambda/langtools/dist $ ./bin/javac Test.java
>> Test.java:62: A lambda expression must be start with the '#{' token (no separators)
>>               t = new Thread(#Test.foo);
>>                              ^
>> Test.java:62: '{' expected
>>               t = new Thread(#Test.foo);
>>                               ^
>> Test.java:62: ';' expected
>>               t = new Thread(#Test.foo);
>>                                       ^
>> 3 errors
>
>
> And the second:
>> markus at ares ~/workspace/jdk7-lambda/langtools/dist $ ./bin/javac Test.java
>> An exception has occurred in the compiler (1.7.0-internal). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
>> com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.sun.runtime.ProxyHelper not found
>
>
> javac has been built from a hg clone of langtools using "ant
> -Dboot.java.home=<SYSTEM_JDK6> -Dtarget.java.home=<JDK7_b126>
> build-all-tools"
>
>
> So I wonder: have method references been removed? Has the syntax
> changed? Did I make some stupid mistake?
>
>
>
> Greetings,
>        Markus
>
>


More information about the lambda-dev mailing list