transparent lambda

Neal Gafter neal at gafter.com
Wed Dec 30 08:42:23 PST 2009


I'm trying to avoid a "solution" that allows this puzzler to be puzzling:

*#int() two = null;
synchronized int four() {
  if (two == null) two = #() { return 2; };
  return two() + two();
}
public static void main(String[] args) {
  System.out.println(four());
}
*

What does this do?

   1. prints "4"
   2. throws an exception
   3. prints "2"
   4. Sometimes prints "2", sometimes throws an exception
   5. does not compile

If you make statement lambdas transparent, the answer is choice 4: the
method prints "2" on its first execution, and throws an exception (unmatched
transfer) thereafter.

Cheers,
Neal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20091230/5567bab5/attachment.html 


More information about the closures-dev mailing list