我对 java 8 功能非常陌生,并尝试了解默认方法。有没有比使用匿名类更容易通过同一接口的另一个默认方法调用默认方法的方法?例如:
public class Frame{
public static void main(String... args){
Frame.C c= new Frame.C();
c.doSomething();
}
public interface A{
public default void doSomething(){
System.out.println("A");
}
}
public interface B extends A {
@Override
public default void doSomething(){
System.out.println("B");
//is there an easier way to invoke that method??
new B(){}.other();
}
default public void other(){
//doSomething();
System.out.println("other");
}
}
public static class C implements B{
@Override
public void other(){
Lambda.B.super.other();
System.out.println("C");
}
}
}