[英]Default method cannot be static in java interface?
Why can't we create an interface with default static method? 为什么我们不能使用默认静态方法创建接口?
public interface StaticTest {
default static void display() {
System.out.println("Display here");
}
}
Static methods cannot be overridden or inherited in any meaningful sense, and default
methods are there to be overridden or inherited. 静态方法不能以任何有意义的意义被覆盖或继承,而
default
方法将在那里被覆盖或继承。 Just like other non-static interface methods, but default
specifically implies that inheritance is meaningful to this method, which is incompatible with static
. 与其他非静态接口方法一样,但
default
表示继承对该方法有意义,而该方法与static
不兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.