extension method implementations for methods of java.lang.Object
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Aug 19 01:50:10 PDT 2010
On 19/08/10 08:59, 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.
>
The VM extension required to handle extension methods at runtime is not
available yet - as a result it is not possible to get to execute the
above code (or any code containing extension methods) with the right
semantics... in fact, since the runtime infrastructure is missing, the
VM gets method dispatching completely wrong - the invokevirtual
targeting A.equals() is dispatched to Object.equals() while for
A.xequals() the VM complains because it cannot find a suitable
implementation of xequals() inside the instance 'a'.
Maurizio
> -
> Thomas
>
>
More information about the lambda-dev
mailing list