java - 泛型类中具有相同签名的抽象和具体方法

标签 java

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/

相关文章:

java - 如何将数组作为参数传递给 Java 图形函数?

java - 速度空值和空字符串

java - 如何根据按钮操作在框架内切换面板?

java - 改造@GET - 如何显示请求字符串?

java - 对线程应用程序进行单元测试

java - TreeBasedTable 的 Guava TreeRow 没有排序,尽管它实现了 SortedMap?

java - 如何在 Safari 中通过 Javascript 访问 Java 对象

java - Android 中的 HTTP-PUT 请求

java - InputStreamReader, FileInputStream 在中点开始解析文件而不是开始

java - 503 服务对 google 端点不可用