java 接口中的默认方法不能是静态的?
Default method cannot be static in java interface?
为什么我们不能使用默认静态方法创建接口?
public interface StaticTest {
default static void display() {
System.out.println("Display here");
}
}
静态方法不能在任何有意义的意义上被覆盖或继承,default
方法可以被覆盖或继承。与其他非静态接口方法一样,但default
明确表示继承对该方法有意义,与static
.
不兼容
为什么我们不能使用默认静态方法创建接口?
public interface StaticTest {
default static void display() {
System.out.println("Display here");
}
}
静态方法不能在任何有意义的意义上被覆盖或继承,default
方法可以被覆盖或继承。与其他非静态接口方法一样,但default
明确表示继承对该方法有意义,与static
.