What’s the best way to get a Class object for an array type?

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 token class.

(bold emphasis mine)

Leave a Comment