0
0

More than 1 year has passed since last update.

static method of interface

Last updated at Posted at 2023-01-10

継承先でstatic method of interfaceは、利用できない
static method of interfaceは使用用途としてはfactory的なもの
自分をimplementsしてるクラスをnewする。
なのでstatic method of interfaceはこのインターフェース内で使用するもの
であり、継承されない

interface A {
    static void method() {
        System.out.println("aaaa");
    }
}
interface B extends A{
}
class C implements A{
}

 public class Outer implements A {
  public static void main(String[] args) {
      A.method();
      B.method();
      C.method();
      method();
  }
}
com/mycompany/mavenproject1/Outer.java:[27,8] シンボルを見つけられません
  シンボル:   メソッド method()
  場所: インタフェース com.mycompany.mavenproject1.B
com/mycompany/mavenproject1/Outer.java:[28,8] シンボルを見つけられません
  シンボル:   メソッド method()
  場所: クラス com.mycompany.mavenproject1.C
com/mycompany/mavenproject1/Outer.java:[29,7] シンボルを見つけられません
  シンボル:   メソッド method()
  場所: クラス com.mycompany.mavenproject1.Outer
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0