我想在类中实现通用接口。 考虑实施此通用接口:在通用类中实现通用接口
public interface Lookup<T>{
public T find(String name);
}
,这是不是通用类实现查找:
public class IntegerLookup implements Lookup<Integer>{
private Integer[] values;
private String[] names;
public IntegerLookup(String[] names, Integer[] values) {......}
//now I want to write the implemented method - find
,我的问题是: 怎么做我需要写这个实施方法? 我需要重写它吗?是?
public Object find(String name){...}
会好吗?或:
public Integer find(String name){...}
Anywhere在超类型中使用'T','Integer'应该用在'Integer'作为'T'类型参数的子类中。 –
为什么你不能只用@Override注解来尝试呢? – Ordous
@SotiriosDelimanolis,但它写入对象不是在超类型T ...或者我错了? –