Lambda and intersection types
Brian Goetz
brian.goetz at oracle.com
Mon Nov 12 12:09:18 PST 2012
So, I was focusing too narrowly on the question the first time I answered.
IF the code compiles, THEN i2 will, at runtime, be an instance of both
I1 and I2.
But, this code may not compile. The likely restriction when applied to
a lambda/method ref conversion, at least initially, is that:
- I1 be a SAM
- I2..In be a "ZAM" (zero abstract method)
- The intersection I1&I2&.. also be a SAM
While the example you post meets the last criteria, it does not meet the
first two.
On 11/12/2012 3:01 PM, Boaz Nahum wrote:
> Yes, but should it be valid code ?
>
> If yes, I2 implements both I1 & I2 or just I2 ?
>
> Thanks
> Boaz
>
>
>
> On Mon, Nov 12, 2012 at 9:55 PM, Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>> wrote:
>
> The back-end work for intersection-typed lambdas is not implemented
> yet...only the compiler front-end work.
>
>
> On 11/12/2012 2:45 PM, Boaz Nahum wrote:
>
> The follwing simple code ...
>
> ==============================__======
> interface I1 {void f();}
>
> interface I2 {
>
> void printMe()default { System.out.println("I2");}
>
> void f();
> }
>
> public static void main(String[] args) {
>
> I2 i2 = (I1 & I2) () -> {};
>
> System.out.println( "i2 is I2=" + (i2 instanceof I2));
>
> i2.printMe();
> }
> ==============================__===
> Output is:
>
> ------------------------------__-------
> i2 is I2=false
> Exception in thread "main"
> java.lang.__IncompatibleClassChangeError: Class
> question.lambda_intersection___types.Q$$Lambda$2 does not
> implement the
> requested interface question.lambda_intersection___types.I2
> ------------------------------__-------
>
> What is the correct behavior ?
>
>
More information about the lambda-dev
mailing list