Hacker News new | past | comments | ask | show | jobs | submit login

Here is an example from Spark Framework (a tiny web framework) written in Java 8.

import static spark.Spark.* ;

public class HelloWorld {

    public static void main(String[] args) {
        get("/hello", (req, res) -> "Hello World");
    }
}

This is more simple as written in previous version and is also consistent with it as it can be written in Java 7 (or earlier) like this.

import static spark.Spark.* ;

public class HelloWorld {

    public static void main(String[] args) {
        get("/hello", new Route() {
	    @Override
	    public Object handle(Request req, Response res) 
                                                throws Exception {
                return "Hello World";
            }
        });
    }
}

You can see how closures in Java actually represent more familiar idea and by omitting unnecessary ceremony do make writing in it more simple.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: