问题描述
我想创建一个泛型ThreadWorker
类,它的泛型类型<T>
接受扩展了<String>
类型的Collection类的类.
I want to create a generic ThreadWorker
class that it's generic type <T>
accepts classes that extends Collection class of type <String>
.
我尝试过:
public class Worker <T extends Collections<String>> extends SwingWorker<VectorDetails , String>
但是我得到一个错误:
The type Collections is not generic; it cannot be parameterized with arguments <String>
也是我写的时候:
public class Worker <T extends Collections> extends SwingWorker<VectorDetails , String>
它可以编译,但是那不是我所需要的,因为可以使用不是String
的其他类的类型来创建此Worker类的实例. (类似于< Integer>
,<Character>
等.).
It compiles fine, but thats not what I need since instances of this Worker class can be created with types of other classes which are not String
. (Like < Integer>
, <Character>
, etc..).
如何强制用户使用扩展/实现包含字符串的Collection类的类型来创建我的类的实例?
How can I force the user to create instances of my class with types that extends/implements Collection class that holds Strings?
推荐答案
您正在寻找什么吗?
class StringCollection<T extends Collection<H>, H extends String> {}
这篇关于如何创建通用< T>类,以便T扩展Collections< String> ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!