IMHO, Concise Instance Creation Expression, the Lee-Lea-Block Proposal for Closures in Java, carries a more hefty price tag than it seems:
- In CICE, at least for Java beginners, it's not obvious at all that a new class is defined and a new object instance created, because of the absence of "new". Even with the "class" in "Anonymous Class", all the time we have been hearing questions like "what's this Foo$1.class thing doing in my classes folder?" Imagine if you have to start the explanation with "yeah, a closure is really a class under the hood..."
- With modern IDEs, it's only a couple of mouse clicks or key strokes to create an anonymous class boilerplate, so I don't see any big saving on that front.
- This one's probably more of a personal taste issue. I just think there is a bit too much magic in the "automatically expose a local variable if it's assigned exactly once" rule. The only gain I can see here is pretty nominal - not having to explicitly type the keyword "final"? Is that really a gain? I am not convinced. For anybody other than the code author, they can no longer tell a variable is final or not when they see something like
because nobody knows maybe a couple of screens later this variable is invoked in a closure.
- I like the ability to declare mutable local variables public and make them available to closures. It scratches the it's-gotta-be-final itch. However, I don't see this particular piece have anything to do with closure. A public local variable can just be as easily accessible from an anonymous class. I'm all for it if this part is singled out as another proposal.
Let me wrap this up with a trivial rant - it doesn't seem objective to compare
for obviously the one liner only makes sense in the simplest examples.