extension method implementations for methods of java.lang.Object
Thomas Jung
thomas.andreas.jung at googlemail.com
Thu Aug 19 06:10:45 PDT 2010
That's okay.
Then the compiler should print a warning that this default method
definition will never apply as all reference types extend
java.lang.Object and the set of problematic methods signatures is
(practically) fixed and known. It could even be considered invalid
code.
Thomas
On 19 August 2010 15:04, Brian Goetz <brian.goetz at oracle.com> wrote:
> That is correct, and does not bother me. The goal of extension methods did
> not include being able to reabstract existing concrete methods from Object.
> We're not trying to solve all the problems of the world in one go...
>
> On 8/19/2010 3:59 AM, Thomas Jung wrote:
>>
>> Hi,
>>
>> with the current prototype it's not possible to define a default
>> implementation for Object#equals.
>>
>> interface A{
>> extension boolean xequals(Object obj) default As.eq;
>> extension boolean equals(Object obj) default As.eq;
>> }
>>
>> static class As{
>> public static boolean eq(A me, Object object){
>> throw new RuntimeException();
>> }
>> }
>>
>> a.equals(new Object()); //passes
>> a.xequals(new Object()); //throws exception
>>
>> This feature is useful if the equals implementation for some subtypes
>> of A can be expressed based on the methods defined in A.
>>
>> Thomas
>>
>
More information about the lambda-dev
mailing list