-
-
Save yujiorama/cacab79d7fdf10cfa9f0 to your computer and use it in GitHub Desktop.
JDK8 で使えるようになったインターフェースの default 実装が、ダイアモンド継承でどうなるのか試した。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface A { | |
String hello(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface B extends A { | |
@Override | |
default String hello() { | |
return "B"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface C extends A { | |
@Override | |
default String hello() { | |
return "C"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class D implements B,C { | |
public static void main(String[] args) { | |
System.out.println(new D().hello()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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