我想通过继承其他普通类(绑定)创建一个新的类,并实现通用接口(不绑定):是否有可能同时和一般地将有界泛型类和泛型接口子类化?
public class Foo1<T extends Bar> {
...
}
public interface Foo2<T> {
...
}
public class ProblemClass<T extends Bar, U>
extends Foo1<T extends Bar> implements Foo2<U> {
...
}
这给了我编译错误。我也尝试过:
public class ProblemClass<T, U>
extends Foo1<T extends Bar> implements Foo2<U> {
...
}
public class ProblemClass<T extends Bar, U>
extends Foo1<T> implements Foo2<U> {
...
}
但是这些都没有工作。
什么是正确的语法来定义我的子类的方式,让我保持键入泛型,让我把他们的类型传递给超类和接口?这甚至有可能吗?
谢谢!
编译器错误? – 2010-03-02 00:28:52
我对这个用例感兴趣。 – 2010-03-02 00:32:05
你的意思是'ProblemClass'对于'T'都具有相同的类型吗?如果你在'Foo1'和'Foo2'中有“匹配”方法,这将是必要的。 – 2010-03-02 00:39:58