Method References
Markus Hauschild
hauschil at fim.uni-passau.de
Mon Jan 24 14:43:57 PST 2011
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