我有几个提供的接口
public interface Finder<S extends Stack<T>,T extends Item> {
public S find(S s, int a);
}
public interface Stack<T extends Item> {
Stack<T> getCopy();
}
Run Code Online (Sandbox Code Playgroud)
和实现第一个的类:
public class SimpleFinder<S extends Stack<T>,T extends Item> implements Finder<S,T>{
public S find(S s, int a){
S stack = ....;
...
stack = s.getCopy(); \\Error: incompatible types
\\ required: S
\\ found: Stack<T>
.....
return stack;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我不能改变任何接口,那么最好的做法是尽可能保持实现的通用性?
编辑
其他一些我无法破解实例化的代码, SimpleFinder<ClassA,ClassB>所以我在实现中也应该有两个泛型类型.