Preparing for the 0.2 draft
Joshua Bloch
jjb at google.com
Tue Feb 2 17:42:18 PST 2010
John,
I realize that this is orthogonal to your main point, but I see you've taken
to dropping the parens on "expression lambdas", e.g., #(int x) 22+x. I find
this terribly hard to read in context. I think it was with good reason that
Alex made the parens mandatory.
I agree that lambda expressions should not be forced to create new
instances. I believe it was a mistake to require (Integer)(128) to create a
new instance, and I don't think we should make that mistake twice.
As for your main point, I'd like it if the syntax for creating an instance
of a Sam type was just as nice as for creating an instance of an ordinary
function type. I realize that this may not be easy, but I think it's worth
trying.
Josh
On Mon, Feb 1, 2010 at 11:28 PM, John Rose <John.Rose at sun.com> wrote:
> Playing with syntax dial settings between "terse" and "verbose" (aka
> "magic" and "tragic"), I just remembered a possible compromise for dealing
> with complicated SAM types. In case it hasn't been proposed yet in the
> context of closures:
>
> Given:
> class MySAM { MySAM(int arg1, int arg2) {...} abstract int
> justOneMethod(int x); }
>
> Then maybe:
> MySAM bar = new MySAM(arg1, arg2) #(int x) 1+x;
>
> As sugar for:
> MySAM bar = new MySAM(arg1, arg2) { int justOneMethod(int x) { return
> 1+x; } };
>
> Making the 'new' explicit defuses the tricky arguments about when the
> object is created, whether the SAM has fields, has a nullary constructor,
> has construction side effects, etc.
>
> -- John
>
> P.S. For interfaces at least, +1 to keep the implicit assignment
> conversion:
>
> interface iSAM { int justOneMethod(int x); }
> Object oof = (iSAM) #(int x) 1+x; // cast conversion implied by implicit
> conversion
>
> And, please be loose about object initialization and identity, when 'new'
> is absent, so implementations can do hoisting & caching without breaking
> spec.:
>
> for (int i = 0; i < 2; i++) {
> iSAM foo = #(int x) 22+x; // initialization => implicit conversion
> if (i == 0)
> System.out.println(foo == oof); // must be false
> else
> System.out.println(foo == oof); // implementation defined result
> oof = foo;
> }
>
>
>
More information about the lambda-dev
mailing list