Lambda and intersection types

Sam Pullara spullara at gmail.com
Mon Nov 12 11:57:34 PST 2012


I thought that one of them had to be a tagging interface with no methods? Shouldn't the compiler have failed to compile this?

Sam

On Nov 12, 2012, at 11:45 AM, Boaz Nahum <boaznahum at gmail.com> 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