A really complicated way to do it in Java:
public class Closures02 {
public static void main(String[] args) {
// no parameters, no statements
System.out.println({ => "Hello World" }.invoke());
// one parameter, no statements
System.out.println({ String greeting => greeting + " " + "World" }.invoke("Hello"));
// two parameters, no statements
System.out.println({
String greeting, String planet => greeting + " " + planet }.invoke("Hello", "World"));
// no parameters, one statement
System.out.println(
{ => System.out.print("Hello"); " " + "World" }.invoke());
// one parameter, one statement
System.out.println({
String separator =>
System.out.print("Hello"); separator + "World"}.invoke(" "));
// two parameters, one statement
System.out.println({
String separator, String planet => System.out.print("Hello"); separator + planet
}.invoke(" ", "World"));
}
}