On 09/13/2011 07:28 PM, Josh Berry wrote:
On Tue, Sep 13, 2011 at 12:49 PM, clay<[email protected]>  wrote:
Ben + Josh, is this an accurate summary of your viewpoints: Java
doesn't have true closures because of the "final" variable requirement
and that any mutability of "closed" variables from the outer
environment requires a level of indirection.

That's a logically consistent argument, although it's real language
lawyer, splitting hairs argument.
I offered that I am the one being pedantic.  :)  How do you feel about
whether or not java has "pass by reference?"  For those that care that
objects are not copied to the stack, the fact that you can not write a
swap is likely a splitting hairs argument, as well.  (For those that
care about the swap, it is key.)

And, yes, I have had several times when I would have liked to do something like:

for (int x = 0; x<  count; x++ ) {
     new Runnable() { public void run() {someFunctionOn(x);}}.run();
}

This would require a closure.  A function literal would help, but a
closure is necessary to make it work.
This works indeed and no closure required:

for (final AtomicInteger x = new AtomicInteger(0) ; x.intValue() < 10; x.incrementAndGet())
          {
            new Runnable()
              {
                @Override
                public void run()
                  {
                    System.err.println(x.intValue());
                  }
              }.run();
          }

--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
[email protected]
http://tidalwave.it - http://fabriziogiudici.it

--
You received this message because you are subscribed to the Google Groups "The Java 
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to