在JLS 8, Section 8.4.8.1有一个声明:
A concrete method in a generic superclass C can, under certain parameterizations, have the same signature as an abstract method in that class. In this case, the concrete method is inherited and the abstract method is not. The inherited method should then be considered to override its abstract peer from C.
任何人都可以为泛型类提供这种参数化的例子吗?我做不到。
最佳答案
也许
public abstract class A<T> {
public abstract void m(T t);
public void m(String s) {}
}
public class B extends A<String> {
}
在这种情况下,B
中的两个方法都将是 void m(String)
。
关于java - 泛型类中具有相同签名的抽象和具体方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700607/