It\'s easy to get a class literal for a class:
String.class
But how can I get a class object for an array type?
This works, but it\
You can simply type
Class<?> clazz = byte[].class;
You can still use a class literal, even for an array type. This compiles just fine.
Class<String[]> clazz = String[].class;
Class<byte[]> clazz2 = byte[].class;
Section 15.8.2 of the JLS states:
A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type
void
, followed by a '.' and the tokenclass
.
(bold emphasis mine)