0

有人知道为什么这不起作用吗?

public class ArrayList<E extends EXTDBinterface<T>> 
    extends java.util.ArrayList<E> implements List<E>,
    RandomAccess, Cloneable, java.io.Serializable {}

Eclipse 抱怨 T 没有被解析为一个类型......是否不可能为扩展类型扩展 ArrayList 类EXTDBinterface<T>?关键是我想T在课堂上使用,但遗憾的是只有这样才有效:

public class ArrayList<E extends EXTDBinterface> 
    extends java.util.ArrayList<E> implements List<E>,
    RandomAccess, Cloneable, java.io.Serializable {}

但是如何在运行时获得泛型类型T... EXTDBinterface

4

3 回答 3

3

First doesn't work cause you didn't set type T. Also you don't need to extend and implement all stuff again cause ArrayList has had this yet. Write, for example:

class ArrayList<T,E extends EXTDBinterface<T>> 
extends java.util.ArrayList<E>{}
于 2013-01-09T09:58:18.553 回答
0

如何在运行时获取 EXTDBinterface 的泛型类型 T

鉴于 Java 使用类型擦除,你不能这样做。如果您需要实际类型,则必须将其传入(通常作为Class-typed 参数)

于 2013-01-09T09:51:53.047 回答
0

您必须定义T为类的类型参数

public class ArrayList<T, E extends EXTDBinterface<T>> 
    extends java.util.ArrayList<E> implements List<E>,
    RandomAccess, Cloneable, java.io.Serializable {}
于 2013-01-09T09:52:04.543 回答