Project Lambda: Java Language Specification draft

Neal Gafter neal at gafter.com
Sat Jan 23 11:21:51 PST 2010


On Fri, Jan 22, 2010 at 5:36 PM, Neal Gafter <neal at gafter.com> wrote:
> Where in the caller are exceptions that were declared in the throws
> clause of the SAM's constructor checked?
>
> You need to specify the runtime behavior of this conversion (when the
> constructor is invoked is observable).

To elaborate on this concern, consider the following

public abstract class SAM {
  public SAM() throws IOException {
    if (true) throw new IOException();
  }
  public abstract int f();
}

public class Main {
  public static void main(String[] args) {
    SAM sam = #()(3);
    int x = sam!();
    System.out.println(x);
  }
}

The "main" method must throw the exception IOException (and not print
anything), even though "throws IOException" is not in the signature of
"main".  This illustrates that the draft specification undermines
exception checking.

My preferred solution is to restrict SAMs to interfaces.


More information about the lambda-dev mailing list