import java.util.List;
import java.util.Map;
+/**
+ * Some utilities for reflection.
+ *
+ * @author Erik Brakkee
+ */
public class ReflectionUtils {
+
+ public static final List<Class> PRIMITIVE_WRAPPERS = createPrimitiveWrappers();
+
+ private static final List<Class> createPrimitiveWrappers() {
+ Class[] vals = { Boolean.class, Byte.class, Character.class,
+ Short.class, Integer.class, Long.class, Float.class, Double.class };
+ return Arrays.asList(vals);
+ }
+
/**
* Wraps a type by the corresponding wrapper type if it is a primitive type.
*
Class... aExcludedClasses) {
if (aClass.isInterface()) {
throw new IllegalArgumentException(aClass.getName() +
- " is not an interface.");
+ " is an interface.");
}
List<Field> found = new ArrayList<Field>();
getAllFields(aClass, found, Arrays.asList(aExcludedClasses));
getAllFields(superClass, aFound, aExcludedClasses);
}
}
+
+ /**
+ * Checks if a class is a primitive type or wrapper type.
+ *
+ * @param aClass
+ * @return
+ */
+ public static boolean isPrimitive(Class aClass) {
+ if (aClass.isPrimitive()) {
+ return true;
+ }
+ return PRIMITIVE_WRAPPERS.contains(aClass);
+ }
}