0
我有一个非常常见的用例在JAVA泛型泛滥,我无法专注如何这是不可能的。通用类型从实现中的泛型类型的接口
以下示例显示无法在接口中创建通用类型,以便在实现方法中将其作为泛型类型进一步传递。
interface MyInterface <T, I, O>
{
public T method(T arg);
}
abstract class MyAbstractClass <I , O> implements MyInterface<List<?>, I , O>
{
// This cause a syntax-failure! What is wrong with this?
// And how can I manage my Generics like this?
@override
public abstract List<O> method(List<I> arg);
}
class MyImplementation extends MyAbstractClass <String , Integer>
{
List<String> method(List<Integer> arg)
{
// ... implementation
}
}
首先,你的界面不使用其他2种类型。其次,您将List >传递给MyInterface,并在我的抽象类中使用列表和List 分别在该方法中,这是错误的,您应该具有相同类型,无论是O还是I等。 –
Justas