Well, of is apparently a static method that is imported statically, so it can be called without including the class name. I expect var be the same. Both methods should return some type that subsequently called the methods:
public class Printable { public void println(Var var); } public class Fac { public static Printable of(Object o) { return new Printable(o); } public static Var var(Class<?> clazz) { return new Var(clazz); } }
Suddenly:
Fac.of(System.out).println(Fac.var(String.class));
It is valid Java. Using static imports, hey presto:
import static Fac.*; of(System.out).println(var(String.class));
Curly braces are obviously valid Java, as you can add them to any method to help define lexical bindings. This style of API design is called freely and is best demonstrated by the JMock testing library.
By the way, if it is supposed to introduce closures in Java, this is pretty ridiculous - the syntax is incredibly awful. Their I / O example actually made me laugh out loud. Try Scala !
EDIT - two println calls are connected. I suppose, because the first sequence of calls allows the library to capture the variables that you passed as parameters. They are probably written in some ThreadLocal structure. When you call the (also supposedly static) println method, the library uses this data to actually execute the behavior at a later point. In addition, testing is due to the fact that the EasyMock test environment uses a similar mechanism (which uses Java proxies in the background) to capture the expected values.
oxbow_lakes
source share