I tried to google, but the results were quite disappointing: it appears that none of the java.lang.reflect.* classes provides such a functionality. So I did a workaround:
public static Class<?> getArrayClassByComponentType(Class<?> ctype) {
return Array.newInstance(ctype, 0).getClass();
}
As you can see, I create a temporary array of size zero and return its class. Since arrays always have a default constructor, it will always work.
I'm still interested to know, if there is more elegant solution...
No comments:
Post a Comment