클래스에 제네릭 인터페이스를 구현하고 싶습니다. 이 일반적인 인터페이스 구현 고려 :제네릭 클래스가 아닌 일반 인터페이스 구현
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){...}
어디에서나 슈퍼 타입에서'T'가 사용되고'T'의 타입 인자로 Integer를 사용하는 서브 클래스에서'Integer'를 사용해야합니다. –
왜 @Override 주석으로 시도 할 수 없습니까? – Ordous
@SotiriosDelimanolis하지만 슈퍼 유형으로 T가 아니라 오브젝트가 작성되었습니다 ... 또는 잘못 되었습니까? –