Yes, there is an easy way:
public class ClassUtils {
private static final Set<Class<?>> wrapperClasses = new HashSet<Class<?>>();
static {
wrapperClasses.add(Integer.class);
... there are a set number of wrapper classes - add them all here
}
then, create a helper method:
public static boolean isWrapperForPrimitive(Class<?> klass) {
return wrapperClasses.contains(klass);
}
}
The reverse is very easy, Class.isPrimitive():
Determines if the specified Class object represents a primitive type.
There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.
These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.