How to get class object for C [] of this class object for C

I was provided with a java.lang.Class object that relates to C.class . What is the most elegant / efficient way to get java.lang.Class that is related to C[].class ?

I can do this with java.lang.reflect.Array.newInstance(clazz, 0).getClass() , but it doesn’t look very good. Any other options?

+4
source share
1 answer

Whatever way you do it, the code will not look very beautiful. By its very nature, Java code that uses reflection tends to be quite verbose. The best you can do is put this code in a utility method, so ugliness and verbosity will be localized using one method and will not contain the rest of your code.

+1
source

All Articles