hg: lambda/lambda/langtools: Bug fixes:

Howard Lovatt howard.lovatt at gmail.com
Wed Sep 1 21:21:25 PDT 2010


Hi Maurizio,

I guess I find:

il.forEach( #( notUsed ) { throw new Exception(); } );

'overly fussy' and would prefer:

il.forEach( #( notUsed ) { throw new Exception() } );

Could the spec. be changed to say that the body could be empty, a
single expression, *or* a single statement (no semi-colon) or a list
of statements separated by semi-colons including an empty statement
(just a semi-colon) and a single statement (followed by a semi-colon).
That way either of the above forms would be valid.

Cheers,

 -- Howard.

On 30 August 2010 18:35, Maurizio Cimadamore
<maurizio.cimadamore at oracle.com> wrote:
> On 30/08/10 01:55, Howard Lovatt wrote:
>>
>> Hi Maurizio,
>>
>> Latest push is great progress. I particularly like that:
>>
>>       il.forEach( #( notUsed ) { throw new Exception(); } ); // Need
>> to catch the checked exception!
>>
>> now works; but note that it has to be statement (i.e. ; required), any
>> chance of eliminating the semi-colon?
>>
>
> Not sure - the idea is that the body of a lambda can be either an expression
> (w/o terminating semi) or a statement (one or more, terminated by semi). In
> case of a method call, since a method call is an expression statement, you
> can have both the semi-terminated and the non-semi-terminated options; in
> the case of 'throw' which is a plain statement, I think your only option is
> to use a terminating semi-colon.
>>
>> The latest push has a regression:
>>
>> 88:    // Method References, syntax like Javadoc
>> 89:    final ActionListener al4 = Main#print( ActionEvent );
>> 90:    b1.addActionListener( al4 );
>> 91:    b1.doClick();
>>
>> This compiles, but when run I get:
>>
>> Exception in thread "main" java.dyn.WrongMethodTypeException:
>> (Ljava/dyn/MethodHandle;Ljava/awt/event/ActionEvent;)V cannot be
>> called as
>> (Ljava/dyn/MethodHandle;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
>>        at sun.dyn.FromGeneric$A2.invoke_I2(FromGeneric.java:533)
>>        at java.dyn.MethodHandle.invokeVarargs(MethodHandle.java:332)
>>        at com.sun.runtime.ProxyHelper$1.invoke(ProxyHelper.java:61)
>>        at $Proxy0.actionPerformed(Unknown Source)
>>        at
>> javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2015)
>>        at
>> javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2338)
>>        at
>> javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
>>        at
>> javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
>>        at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
>>        at javax.swing.AbstractButton.doClick(AbstractButton.java:356)
>>        at lambdas.Main.lambdas(Main.java:91)
>>        at lambdas.Main.main(Main.java:22)
>>
>
> Damn :-)
> thanks again for the feedback!
>>
>> Note that:
>>
>>     // Method References, syntax like Javadoc
>>     final ActionListener al4 = Main#print( ActionEvent );
>>     b1.addActionListener( al4 );
>> //    b1.doClick();
>>     b1.removeActionListener( al4 );
>>
>> Now runs OK (thanks), i.e. the remove now works (the error above is
>> caused when doClick runs).
>>
>>
>
> Maurizio
>>
>> Cheers,
>>
>>   -- Howard.
>>
>
>



-- 
  -- Howard.


More information about the lambda-dev mailing list