首页 > 解决方案 > 带参数的 Java 泛型 - 继承

问题描述

我有以下代码:

public class Inheritance {

    class A<T,U,V>{

    }

    class B<T,U,V> extends A<T,U,T>{        

    }
}

有人可以解释一下,它实际上是如何工作的吗?B 类是否仅扩展 A 类,哪些参数是“T,U,T”,或者它扩展了实际的 A“T,U,V”类?

标签: javagenericsinheritancesubclasssubtype

解决方案


A's T= B' T
As U= B' U
As V= B'sT

B<String, Integer, Void> b = null;
A<String, Integer, String> a = b;

推荐阅读