1、示例接口
public interface Foo { default void doThat() { // ... } } public interface Bar { default void doThat() { // ... } }
下面将不能编译
public class FooBar implements Foo, Bar{
}
2、重写方法消除歧义
1)调用Bar的doThat方法
public class FooBar implements Foo, Bar{
@Override
public void doThat() {
Bar.super.doThat();
}
}
2)调用Foo的doThat方法
public class FooBar implements Foo, Bar { @Override public void doThat() { Foo.super.doThat(); } }
3)完全重写的doThat方法
public class FooBar implements Foo, Bar { @Override public void doThat() { // ... } }