extension method implementations for methods of java.lang.Object

Thomas Jung thomas.andreas.jung at googlemail.com
Thu Aug 19 00:59:00 PDT 2010


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