Method References

Markus Hauschild hauschil at
Mon Jan 24 14:43:57 PST 2011


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(;

or this:
> Thread t = new Thread(Test#foo);

As seen on the Method References chapter of

But the first one results in:
> markus at ares ~/workspace/jdk7-lambda/langtools/dist $ ./bin/javac
> A lambda expression must be start with the '#{' token (no separators)
>               t = new Thread(;
>                              ^
> '{' expected
>               t = new Thread(;
>                               ^
> ';' expected
>               t = new Thread(;
>                                       ^
> 3 errors

And the second:
> markus at ares ~/workspace/jdk7-lambda/langtools/dist $ ./bin/javac
> An exception has occurred in the compiler (1.7.0-internal). Please file a bug at the Java Developer Connection (  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
>$CompletionFailure: class file for com.sun.runtime.ProxyHelper not found 

javac has been built from a hg clone of langtools using "ant<SYSTEM_JDK6><JDK7_b126>

So I wonder: have method references been removed? Has the syntax
changed? Did I make some stupid mistake?


More information about the lambda-dev mailing list