Building Lambda and a Closure Question
Brian Goetz
brian.goetz at oracle.com
Sun Nov 20 10:11:32 PST 2011
First, the defender-prototype / weaving is only needed if you want to
experiment with extension methods. If you just want to experiment with
lambdas and method references, you don't need this part.
As far as the how-to, you are probably better off pointing people to the
downloadable binaries, which are pre-woven:
http://jdk8.java.net/lambda/. There have also been some instructions
posted recently about getting the prototype weaver to compile; scan the
reset list traffic for those.
To your question:
> final C c = () -> { return "Hello World"; }; //<- had to put
> semi-colon here. In the spec, no semi-colon is shown.
Yes, the expression () -> { stuff } is the rhs of the assignment; the
assignment statement "c = expr" needs a semicolon after it.
On 11/20/2011 12:33 PM, David Harrigan wrote:
> Hi,
>
> A new user :-) (well, at least to jdk8).
>
> I've put together a "how-to" for getting JDK8 up and running with
> Lambda[1], but I had to modify a few things and I wanted to check
> before I published my blog posting.
>
> When trying to get the project to compile, I hit a stumbling block on
> reweaving using the jsr335-agent. Some digging around eventually led
> me to clone the
> defender-prototype[2] project. Instructions aren't available for
> including this dependency (I ack-grep'ed the source tree - no
> reference). I wasn't even sure where to put
> the cloned defender-prototype directory but putting it at same level
> as the cloned lambda repo seemed to work. My blog contains
> instructions on getting this project.
>
> However, compiling defender-prototype failed since there is a
> depedency on including some classes from asm. I looked at the
> build.xml file, saw it referenced
> asm-all-4.0.jar and proceeded to download that. Unfortnately, even
> with this jar it failed to compile since in asm-all-4.0 they have
> changed some package names
> and removed some classes. Eventually I found out that asm-all-3.3.1
> included the necessary classes to compile. It seems that by creating a
> symlink from asm-all-3.3.1
> to asm-all-4.0 and attempting to recompile the defender-prototype
> project worked. Then, recompiling the lambda project worked. Great
> news!
>
> 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?
> Since 4.0 doesn't contain the
> necessary classes to compile defender-prototype, this leads either to
> a yes answer, or a hand-rolled asm-all-4.0 jar (unlikely). I would
> like a bit of clarification on this
> please.
>
> 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());
>
> }
> }
>
> Thank you all in advance.
>
> [1] http://hg.openjdk.java.net/lambda/lambda
> [2] http://hg.openjdk.java.net/lambda/defender-prototype
>
More information about the lambda-dev
mailing list