전달한 특정 유형의 Vector를 리턴하는 함수를 작성하고 싶습니다. 예를 들어 :자바에서 일반 함수 작성하기
// Here getNewVector(<ClassType>) should return me an integer Vector.
Vector<Integer> myIntVector = getNewVector(Integer.class);
//should get a String vector in this case and so on.
Vector<String> myStringVector = getNewVector(String.class) ;
나는 특정 클래스 형의 새로운 벡터를 반환 할 수있는 방식으로 getVector(Class classType)
을 구현하려는. 반사를 사용하지 않고 클래스 이름을 String으로 전달하지 않고 어떻게 구현할 수 있습니까? (위의 예에서 언급 한 클래스 유형 만 전달하고 싶습니다.)
실제로 getVector) 다소 비슷합니다.
Vector<T> getVector(T t) {
return new Vector<t>();
}
나는 Vector 사용에 대해 두 번 생각할 것이다. 대신 목록 사용을 고려 했습니까? – KidTempo