我有一个如下界面,
public interface MethodExecutor {
<T> List<T> execute(List<?> facts, Class<T> type) throws Exception;
}
另外,我有一个如下的通用实现,
public class DefaultMetodExecutor implements MethodExecutor {
public <T> List<T> execute(List<?> facts, Class<T> type) throws Exception
{
List<T> result = null;
//some implementation
return result;
}
}
到目前为止,没有编译问题,
但该接口的具体实现编译失败,如下图所示。
public class SpecificMetodExecutor implements MethodExecutor {
public <Model1> List<Model1> execute(List<Model2> facts, Class<Model1> type) throws Exception
{
List<Model1> result = null;
//some implementation specific to Model1 and Model2
return result;
}
}
如何为某些已定义的对象实现此接口?我需要去学习类级别的泛型吗?