defender methods and method of Object
bitter_fox
bitterfoxc at gmail.com
Fri Mar 2 08:08:02 PST 2012
Hi,
You have to override toString in A to use the default implementation, in
this case, using the syntax "Interface.super.method()":
(because the definition of super-class is preferred if the extended
definitions from super-class and super-interface are clashing)
public class A implements Foo
{
public String toString()
{
return Foo.super.toString();
}
}
new A().toString(); // returns "Foo"
However, this calling would be StackOverflowError because the syntax may be
only on "Syntax" and be not implemented for byte code.
I can't judge that semantics is right or wrong, so I only refer to the way
to override.(Although I think it is right...)
Excuse me if you already know the way.
Regards,
bitter_fox
2012/3/2 Rémi Forax <forax at univ-mlv.fr>
> Hi all,
> With the current semantics, there is no way to override a method of
> java.lang.Object with a default method.
> By example,
>
> interface Foo {
> public String toString() { return "Foo"; }
> }
> public class A implements Foo {
> }
> ...
> A a = new A();
> a.toString() -> calls Object::toString()
>
> I think it's not the right semantics because you can all on an interface
> all the method of java.lang.Object so an interface is a type more specific
> than Object.
>
> Rémi
>
>
>
More information about the lambda-dev
mailing list