Project Lambda: Java Language Specification draft

Zdenek Tronicek tronicek at fit.cvut.cz
Mon Jan 25 08:05:50 PST 2010


Neal Gafter napsal(a):
> 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.

Right. It is not specified well. However, the correction is not difficult:

SAM sam = #()(3);

is desugared to

SAM sam = new SAM() {
  public int f() { return 3; }
}

Z.
-- 
Zdenek Tronicek
FIT CTU in Prague



More information about the lambda-dev mailing list