Converting Java 8 syntax to Java 7
By Tim on Thursday, January 17 2013, 23:00 - Development - Permalink
A project I was working on finished up abruptly, and I found myself with some spare time over the last few weeks, so I decided to test out a new idea - a utility to convert Java 8 syntax into Java 7
For the most part, this is simply an experiment - to see how difficult it would be to write such a utility (and the short answer is that it's difficult to do well, but certainly not impossible), but it has the potential to be useful for supporting lambda-based code in environments that do not (yet) have support for Java 8.
I have a working prototype, that supports conversion of a subset of Java 8 features. And by a subset, I mean essentially 1...
It can convert a variable declaration for a functional interface with a lambda initializer into a anonymous inner class. e.g.
Callable<String> callable = () -> "abc" ;
is converted to
Callable<String> callable = new Callable<String>() {
public String call() throws java.lang.Exception {
return "abc";
}
};
It's a long way from being feature complete, but it's usable (within the scope of what has been implemented). It looks like I'll be starting a new role next week, so that may reduce my time to work on this project for a little while - I wanted to get it published before that happened.
Documentation is available here.
Feedback (and/or patches) highly desired.