Building Lambda and a Closure Question

Mike Duigou mike.duigou at oracle.com
Sun Nov 20 10:13:56 PST 2011


On Nov 20 2011, at 09:33 , David Harrigan wrote:

> Hi,
> 
> A new user :-) (well, at least to jdk8).

Welcome!


> My first question is:
> 
> Is the reference to asm-all-4.0 in build.xml in defender-prototype
> really a reference to asm-all-3.3.1 but symlinked to asm-all-4.0?

The defender prototype was developed against ASM 4.0 RC1 which does have the missing classes that later builds lack.

The prototype hasn't been updated to use the ASM 4.0 final yet. As a temporary component it's possible that it might not be updated (patches welcome of course) to use current versions of ASM.

> My next (and last question) is:
> 
> I wrote a very simple closure with the current Lambda Specification
> 0.4.2 in front of me. I could only get my closure to compile if I
> followed the closure block with a
> semi-colon. The examples in the spec don't include this. I'm assuming
> this semi-colon was left off for readability - can this be confirmed?
> 
> public class Closures {
> 
>    interface C {
>        String c();
>    }
> 
>    public static void main(final String[] args) {
> 
>        final C c = () -> { return "Hello World"; }; // <- had to put
> semi-colon here. In the spec, no semi-colon is shown.
>        System.out.println(c.c());
> 
>    }
> }

THe semicolon in this case is to end the statement. Consider if you were to add another variable "cc"

final C cc = c;

The lambda body and the "c" reference are equivalent. So the final semicolon in your assignment to c is fulfilling the same role as the semicolon in the cc asisgnment, ending the statement. It's not part of the lambda.

BTW, your lambda could be simpler as you can use expression form for this case:

final C c = () -> { "Hello World" };

Mike


More information about the lambda-dev mailing list