Hacker News new | comments | show | ask | jobs | submit login

None of these closures actually close over any state. Is that feature going to exist, or are these really just C-style function pointers?



If this is equivalent to anonymous classes, then it can close over final references.

E.g.,

  public class Ref<T> {
     private T t;
     public Ref(T initial) { t = initial; }
     public T get() { return t; }
     public void set (T t) { this.t = t; }
  }

  public Callable<Integer> makeIncrementer(int initial) {
      final Ref<Integer> ref = new Ref<Integer>(initial);
      
      return new Callable<Integer> () {
         public Integer call() {
             int rv = ref.get();
             rv += 1;
             ref.set(rv);
         }
     }
  }
Nonetheless if the reference closed over still has to be final (e.g., I can't just give it an Integer) this is merely syntactic sugar over what Java already has. Perl had this for ages:

  sub make_incrementer {
      my $i = shift;

      return sub { return $i++; }
  }
 
Too little, too late. I am almost certainly using Scala (or Clojure) for any future JVM projects (unless there's a good reason not to).




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: