I want the underlying class from a static array. For example if it says String[].class I want to get String.class
String[] foo = new String[0];
System.out.println(foo.getClass());
Output
class [Ljava.lang.String;
Class<?> type = foo.getClass().getComponentType();
System.out.println(type); // class java.lang.String
From the docs:
Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null.
foo is an array, you might want to first check foo.getClass().isArray(), instead of testing whether getComponentType() returns null.