Skip to content

Commit

Permalink
handles primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
n9Mtq4 committed Jun 16, 2015
1 parent 5fd6960 commit f3336a1
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/com/n9mtq4/reflection/ReflectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2354,9 +2354,40 @@ public static Class getClassByFullName(String className) {
public static Class[] getClassParams(Object[] params) {
Class[] classParams = new Class[params.length];
for (int i = 0; i < classParams.length; i++) {
classParams[i] = params[i].getClass();
Class clazz = params[i].getClass();
if (isPrimitive(clazz)) {
classParams[i] = getPrimitive(clazz);
}else {
classParams[i] = clazz;
}
}
return classParams;
}

public static boolean isPrimitive(Class clazz) {
return getPrimitive(clazz) != null;
}

/**
* Primitive types have two classes in java.
* The primitive one (ie. int.class) and the
* Object one (ie. Integer.class).
* This takes the Object one (ie. Integer.class)
* and returns a primitive one (ie. int.class)
*
* @param clazz The Object class to get the primitive version
* @return The Primitive version, or null if there isn't one
* */
public static Class getPrimitive(Class clazz) {
if (clazz == Boolean.class) return boolean.class;
if (clazz == Byte.class) return byte.class;
if (clazz == Character.class) return char.class;
if (clazz == Double.class) return double.class;
if (clazz == Float.class) return float.class;
if (clazz == Long.class) return long.class;
if (clazz == Short.class) return short.class;
if (clazz == Integer.class) return int.class;
return null;
}

}

0 comments on commit f3336a1

Please sign in to comment.