Optional brackets around lambda expression
Steven Simpson
ss at comp.lancs.ac.uk
Wed Jun 15 14:25:40 PDT 2011
On 15/06/11 21:42, Pavel Minaev wrote:
> Note that this applies also to "Redmond syntax" in general; e.g.:
>
> new User().use(x => x + "a string");
Ah - I only looked at the options in the original "Syntax poll", where
expressions were in braces for Redmond.
> On Wed, Jun 15, 2011 at 1:35 PM, Yuval Shavit <yshavit at akiban.com
> <mailto:yshavit at akiban.com>> wrote:
>
> What would happen with something like:
>
> public interface Sam {
> String doSomething(String arg);
> }
> public class User {
> public void use(Sam sam) { System.out.println("saw a sam"); }
> public void use(String string) { System.out.println("saw a
> string"); }
> }
>
> new User().use( #(x) x + "a string" );
>
> In that context, which are we passing?
> - lambda that takes a String, concatenates "a string" to it and
> returns
> the result
>
Yes.
> - a string consisting of (lambda x -> x).toString() concatenated
> with "a
> string"
>
For that, you write (#(x) x) + "a string" - ordinary expression brackets
can still be used, but are only necessary in the more contrived cases.
More information about the lambda-dev
mailing list