SAM conversion of abstracted methods from java.lang.Object

Alex Buckley alex.buckley at oracle.com
Wed Aug 25 17:59:27 PDT 2010


On 8/25/2010 5:32 PM, Rémi Forax wrote:
> So K is not a SAM but K2 is a SAM ?
>    interface I { I m(); }
>    interface J { J m(); }
>    interface K extends I, J { }
>    interface K2 extends I, J { K2 m(); }
> This seems Ok.

K is illegal since it inherits two override-equivalent methods (I.m and 
J.m) but neither is return-type-substitutable for the other.

K2 is fine, and is a SAM.

> But with your definition class A is not a SAM.
> abstract class A implements I {
>    public abstract A m();
> }
> Here, I don't understand why ?

A.m overrides I.m, and happily A.m is return-type-substitutable for I.m, 
so there is exactly one non-generic abstract method in A. If A had a 
no-args constructor, it would be a SAM type.

Alex


More information about the lambda-dev mailing list