extension method implementations for methods of java.lang.Object

Brian Goetz brian.goetz at oracle.com
Thu Aug 19 06:04:08 PDT 2010


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