writing generic function in java

7331

New Member
I want to write a function which would return me a Vector of the specified type which I pass to it. For example:\[code\]// 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) ; \[/code\]I want to implement \[code\]getVector(Class classType)\[/code\] in such a way so as to return a new vector of that particular class type. How can we achieve it without using reflections and by not passing the class name as a String(I would like to pass the class type only as I had mentioned in the example above.)Actually, I want a function getVector() somewhat like this..\[code\]Vector<T> getVector(T t) { return new Vector<t>();}\[/code\]
 
Top