Object Teams now has Lambdas (and more)
In a previous post I announced that the Luna version of Object Teams will incorporate support for Java 8.
Now that the big rush towards March 18 is over, I took stock how Object Teams fits into the Luna stream, which finally contains all the bits for Java 8 support. The result:
This means, you can now use lambda expressions and more even in OT/J programs, here’s a witness:
While this program may not make a lot of sense, it demonstrates a funny piece of syntax. Here’s what you see:
- The regular class PersonCollection offers a method restrict that takes an argument of a functional type (Predicate)
- Role Club.Members is played by PersonCollection and makes the base method available via a callout binding (lines 19 f)
- The role wants to pass just an int value, where the base method expects a Predicate.
- This incompatibility is bridged by a parameter mapping that maps a lambda expression to the expected parameter (line 20).
This looks funny, because two different uses of the token ->
meet on a single line: the first ->
is part of the lambda expression, separating the parameter from the body, the second ->
is part of the parameter mapping, mapping the expression on the left to the parameter on the right.
Were I to chose the syntax in a green field situation, I would certainly not use the same token for such different purposes. But since we’re basically merging two independent language extensions I had no choice. After some worries that the combined language might not be parseable I’m much relieved to see it actually working!
A very similar situation actually exists concerning type annotations. More on that in a future post.
Remaining steps towards Luna
Merging the entire BETA_JAVA8 code base from JDT into Object Teams is done, but a few regressions (< 30 out of 84,000+ tests) remain from that exercise. But compared to the original JDT efforts for Java 8 this truly is peanuts 🙂
We only have one hurdle still to jump: our bytecode weaver is based on BCEL, for which no update for Java 8 is in sight. This means: we cannot weave into class files that use the Java 8 bytecode version, bummer!
So the real interesting question will be: can we get the long announced alternate weaver using ASM up to speed in time for Luna? I think we can, but it won’t hurt if you wish me luck in this endeavour.
And yes: one day I should start writing meaningful examples using Java 8 features in OT/J code…
Leave a Reply