Lambda Expressions for JRE 5

3,759 views
Skip to first unread message

Sam Reid

unread,
Mar 5, 2012, 11:22:42 PM3/5/12
to java...@googlegroups.com
I compiled my first lambda expression (function literal) using javac from OpenJDK 8, and it was very nice. However, we have many (more than a thousand) clients who are still living with JRE 5, and I don't want to drop support for them or force them to upgrade.  I tried specifying -target 1.5, but it said targeting 1.5 was not supported if lambda expressions were in the code.  Do you know of any ways I will be able to use lambda expressions in Java and still being able to accommodate my 1.5 clients?  I recall something from years ago called RetroWeaver that let you use 1.5 features (generics, boxing) and back-compile to run on 1.4 runtime.  Are there any equivalent tools that will let me use Java 1.7 on 1.5 runtime?  Or do you know any other ways around this?

Thanks!
Sam

Martijn Verburg

unread,
Mar 6, 2012, 4:20:18 PM3/6/12
to java...@googlegroups.com
Hi Sam,

I Am Not A Lambdas Expert (IANALE) but assuming they go with an
invokedynamic implementation (which at this stage is likely for
performance reasons) then there won't be the possibility of having 1.5
compatibility, unless of course they have a separate anonymous inner
class implementation for older versions of Java.

Either way, best place to ask this Q is on the lambda-dev OpenJDK mailing list.

Cheers,
Martijn

> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/javaposse/-/mncTZ2GGz6cJ.
> To post to this group, send email to java...@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.

Kevin Wright

unread,
Mar 6, 2012, 7:13:17 PM3/6/12
to java...@googlegroups.com
Some sort of retro-lambdas is certainly possible in theory, re-writing invokedynamic (or whatever other new bytecodes are used) as anonymous classes implementing some SAM type.  This is the approach taken by many of the other languages already supporting lambdas/closures on the Java platform.

The devil is in the details though; any such retro-enabling transform would have to pay a great deal of attention to correctness.  If you also consider the performance profile to be part of any correctness guarantee then this becomes extra-specially tricky.  Optimising for performance on the JVM can be challenging at the best of times!

If interested, it's worth reading Charles Nutter's blog/articles on optimising JRuby and Mirah for the platform.  There's some very interesting and enlightening revelations in there.

Sander Mak

unread,
Mar 7, 2012, 10:04:59 AM3/7/12
to java...@googlegroups.com


On Tuesday, March 6, 2012 10:20:18 PM UTC+1, Martijn Verburg wrote:
Hi Sam,

I Am Not A Lambdas Expert (IANALE) but assuming they go with an
invokedynamic implementation (which at this stage is likely for
performance reasons) then there won't be the possibility of having 1.5
compatibility,

Remi Forax was doing some work on a JSR-292 backport though, that might help: http://code.google.com/p/jvm-language-runtime/downloads/list
 
Reply all
Reply to author
Forward
0 new messages