上級 › default メソッドの衝突と解決 › パターン4
default メソッドの衝突と解決
複数のインターフェースから同名を継承すると衝突します。
1 interface MathUtils { 2 static int square(int n) { return n * n; } 3 } 4 public class Main implements MathUtils { 5 public static void main(String[] args) { 6 System.out.println(__________.square(5)); ^ 7 } 8 }
Main.java:5: error: cannot find symbol
symbol: method square(int)
空欄を埋めてビルドを通す
インターフェースのstaticメソッドは、defaultメソッドと違って実装クラスのインスタンスからは呼べません。インターフェース名を直接指定します。
次の問題