Skip to content

Instantly share code, notes, and snippets.

@yujiorama

yujiorama/A.java Secret

Last active August 29, 2015 13:57
Show Gist options
  • Save yujiorama/cacab79d7fdf10cfa9f0 to your computer and use it in GitHub Desktop.
Save yujiorama/cacab79d7fdf10cfa9f0 to your computer and use it in GitHub Desktop.
JDK8 で使えるようになったインターフェースの default 実装が、ダイアモンド継承でどうなるのか試した。
public interface A {
String hello();
}
public interface B extends A {
@Override
default String hello() {
return "B";
}
}
public interface C extends A {
@Override
default String hello() {
return "C";
}
}
public class D implements B,C {
public static void main(String[] args) {
System.out.println(new D().hello());
}
}
$ javac A.java B.java C.java D.java
D.java:1: エラー: クラス Dは型BとCからhello()の関連しないデフォルトを継承します
public class D implements B,C {
^
エラー1個
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment