interface MyInterface {
default int someMethod() {
return 0;
}
int anotherMethod();
}
class Test implements MyInterface {
public static void main(String[] args) {
Test q = new Test();
q.run();
}
@Override
public int anotherMethod() {
return 1;
}
void run() {
MyInterface a = () -> someMethod();
System.out.println(a.anotherMethod());
}
}
执行结果将为0,虽然我预期为1.我不明白为什么不返回重写方法的结果,而返回默认方法的结果.