Preparing for the 0.2 draft
John Rose
John.Rose at Sun.COM
Mon Feb 1 23:28:02 PST 2010
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