让我们假设我有这样的代码:为什么接口方法在实现接口的类中不能是静态的?
public interface JustAnInterface {
void doSomething();
}
public class JustAnInterfaceImplementation implements JustAnInterface {
@Override
public static void doSomething() {
}
}
为什么static doSomething()
方法显示错误“方法不从其超覆盖法”?
因为在接口中定义的方法是非静态的。你的问题基本上是循环的。 – EJP
静态方法通常无效。它们属于它们所定义的类别,仅属于该类别,并不构成层次结构的一部分。 – Michael
方法签名与接口不同。 –