Jeff Schwab
3/6/2009 12:48:00 PM
Robert Klemme wrote:
> On 06.03.2009 00:28, Sandor Szücs wrote:
>> It's some years ago but as I looked into function parameters in Java it
>> was just a pain to use.
ITYM "lambda expressions," not "function parameters."
> I'd concede that it is more
> cumbersome than in Ruby with blocks because of the limitations
> (variables used inside the anon class must be final for example).
Agreed, but Ruby blocks and Java anonymous classes are subtly different
things. Java anonymous classes were meant to be an approximation to
closures.
When a closure is called, it still "lives" in the scope that created it.
Java's anonymous classes don't really have access to their parent
scopes, but Java fakes it by copying data before the scope goes away.
Of course, the copies have to be immutable, or else two AC instances
from the same creating scope could tell that they weren't really
accessing the same variables.
Ruby blocks are something completely different, but IMO, they're more
like closures than Java ACs, because they execute in the scope where
they are created. They're not really lambdas at all, though, because
you can't pass them around as objects. Of course, Ruby also supports
real closures, and class Proc fills a similar role to Java ACs.