SAM conversion of abstracted methods from java.lang.Object
Rémi Forax
forax at univ-mlv.fr
Wed Aug 25 17:32:48 PDT 2010
Le 26/08/2010 01:43, Alex Buckley a écrit :
> On 8/25/2010 6:12 AM, Maurizio Cimadamore wrote:
>
>> the current definition of SAM conversion does not consider Object
>> methods as possible targets for lambda conversion.
>>
> True. The current definition allows multiple abstract methods such that
> any non-Object methods are basically the same (this was to admit
> Comparator as SAM); but it doesn't require there to be an abstract
> _non-Object_ method in the first place (this matters for interfaces),
> and it discriminates against Object methods later (this matters for
> classes).
>
> So let's start from the beginning. Here is how things should be:
>
> abstract class Foo {} // Not a SAM type; not enough abstract methods
> interface Foo {} // Not a SAM type; no discernable abstract method
>
> abstract class Foo { public abstract boolean equals(Object object); }
> // SAM type; Foo has one abstract method
>
> abstract class Bar extends Foo { public abstract String toString(); }
> // Not a SAM type; too many abstract methods
>
> abstract class Quux {
> public abstract boolean equals(Object object);
> public abstract String toString();
> }
> // Not a SAM type; too many abstract methods
>
> interface Foo { boolean equals(Object obj); }
> // Not a SAM type; too many abstract methods
>
> interface Bar extends Foo { int compare(T o1, T o2); }
> // SAM type; Bar has one abstract non-Object method
>
> interface Comparator<T> {
> boolean equals(Object obj);
> int compare(T o1, T o2);
> }
> // SAM type; Comparator<T> has one abstract non-Object method
>
> The definition becomes:
>
> --
> A SAM (Single Abstract Method) type is an interface type or a
> top-level or member class type, that has zero generic abstract
> methods, and:
>
> - if a class type, the class is declared abstract, has a no-args
> constructor, and has exactly one non-generic abstract method;
>
> - if an interface type, the interface has one or more non-generic
> abstract methods M1..Mn (n>=1) that are not override-equivalent to
> any method in java.lang.Object; furthermore, if Mi is not
> override-equivalent to any method in java.lang.Object and Mj is not
> override-equivalent to any method in java.lang.Object, either i==j
> or the signatures of Mi and Mj are override-equivalent.
>
> In the type T obtained from applying capture conversion to the SAM
> type, let M be the set of abstract methods in T if T is a class type;
> otherwise, if T is an interface type, let M be the set of abstract
> methods in T that are not override-equivalent to any method in
> java.lang.Object.
> --
>
> Alex
>
Alex,
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.
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 ?
Rémi
More information about the lambda-dev
mailing list