I have a class as follows:
public class MyConverter {
public <T> T convert (Object o, String typeidentifier, T dummy)
{
... do some conversions such as a java array to an ArrayList or vice versa
... based on a typeidentifier syntax similar to Class.getName() but which
... embeds information about generic subtypes
}
}
and want to be able to do something in common:
int[] ar = {...};
ArrayList<Integer> dummy = null;
Integer elem = MyConverter.convert(ar, "java.util.ArrayList<Integer>", dummy)
.get(15);
That is, Tin convert can itself be a common instance, and I found that in order for this purpose to work, I have to pass a fully typed layout, since the ArrayList.classjava compiler will not give enough information what ArrayList<Integer>if I used Class<T> dummyclsinstead T dummy.
Am I missing something? Is there a way for both recording and invoking conversion without using a dummy?
source
share