default methodとclass method、同じ名前で定義し
implements, extendsすると、class methodが優先となる。
default methodは消失
B.methodがprivateの場合、compileはA.methodが使われてnormal end.
実行時にIllegalAccessError
interface A {
default void method() {
System.out.println("aaaaA");
}
}
class B{
public void method(){
System.out.println("aaaaB");
}
}
class C extends B implements A{}
class D implements A{}
public class Outer {
public static void main(String[] args) {
Method m[] = new C().getClass().getMethods();
for(Method mc:m) {
System.out.println(mc);
}
System.out.println("----------------------");
m = new D().getClass().getMethods();
for(Method mc:m) {
System.out.println(mc);
}
}
}
public void com.mycompany.mavenproject1.B.method()
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public boolean java.lang.Object.equals(java.lang.Object)
public java.lang.String java.lang.Object.toString()
public native int java.lang.Object.hashCode()
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
----------------------
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public boolean java.lang.Object.equals(java.lang.Object)
public java.lang.String java.lang.Object.toString()
public native int java.lang.Object.hashCode()
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
public default void com.mycompany.mavenproject1.A.method()