Method References

Rémi Forax forax at univ-mlv.fr
Mon Jan 24 15:15:43 PST 2011


Recently Sam Pullara wrote a nice blog post explaining how to get lambda 
and extension method to work.

http://www.javarants.com/2011/01/22/using-closures-method-handles-and-extension-methods-in-java-8-jsr-335/

cheers,
Rémi

On 01/25/2011 12:05 AM, Håkon Sandsmark wrote:
> 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