|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javautils.Classes
Static utility methods for dealing with classes and reflection.
Note: None of these methods throws checked exceptions.
Checked exceptions will be translated to unchecked RuntimeException
-exceptions. This makes these methods far more
pleasant to use compared to direct use of the Class
-class.
Constructor Summary | |
Classes()
|
Method Summary | |
static java.lang.Class |
asObjectType(java.lang.Class type)
If the given type is a primitive type (say int.class ), returns the corresponding object type (say
Integer.class ). |
static java.lang.Class |
forName(java.lang.String name)
return Class.forName(name); |
static java.lang.String |
getBaseName(java.lang.Class cls)
Returns the last part (the part after the last dot) of the type name. |
static java.lang.reflect.Field |
getField(java.lang.Class cls,
java.lang.String fieldName)
return cls.getField(cls, fieldName); |
static java.lang.Object |
getFieldValue(java.lang.Object obj,
java.lang.String fieldName)
return obj.getClass().getField(fieldName).get(obj); |
static java.lang.reflect.Method |
getMethod(java.lang.Class cls,
java.lang.String methodName)
return getMethod (cls, methodName, null);
|
static java.lang.reflect.Method |
getMethod(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class[] argTypes)
return cls.getMethod(methodName, argTypes); |
static java.lang.reflect.Method |
getMethod(java.lang.Object obj,
java.lang.String methodName,
java.lang.Class[] argTypes)
return getMethod (obj.getClass(), methodName, argTypes);
|
static java.lang.Object |
getStaticFieldValue(java.lang.Class cls,
java.lang.String fieldName)
return cls.getField(fieldName).get(null); |
static java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object self,
java.lang.Object[] args)
return method.invoke(self, args); |
static java.lang.Object |
newInstance(java.lang.Class cls)
return cls.newInstance(); |
static java.lang.Object |
newInstance(java.lang.Class cls,
java.lang.Class[] paramTypes,
java.lang.Object[] params)
return cls.getConstructor(paramTypes).newInstance(params); |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Classes()
Method Detail |
public static java.lang.Class asObjectType(java.lang.Class type)
If the given type is a primitive type (say
int.class
), returns the corresponding object type (say
Integer.class
). Otherwise returns the given type.
public static java.lang.Class forName(java.lang.String name)
return Class.forName(name);
public static java.lang.String getBaseName(java.lang.Class cls)
Returns the last part (the part after the last dot) of the type name.
public static java.lang.reflect.Field getField(java.lang.Class cls, java.lang.String fieldName)
return cls.getField(cls, fieldName);
public static java.lang.Object getFieldValue(java.lang.Object obj, java.lang.String fieldName)
return obj.getClass().getField(fieldName).get(obj);
public static java.lang.reflect.Method getMethod(java.lang.Class cls, java.lang.String methodName)
return getMethod
(cls, methodName, null);
public static java.lang.reflect.Method getMethod(java.lang.Class cls, java.lang.String methodName, java.lang.Class[] argTypes)
return cls.getMethod(methodName, argTypes);
public static java.lang.reflect.Method getMethod(java.lang.Object obj, java.lang.String methodName, java.lang.Class[] argTypes)
return getMethod
(obj.getClass(), methodName, argTypes);
public static java.lang.Object getStaticFieldValue(java.lang.Class cls, java.lang.String fieldName)
return cls.getField(fieldName).get(null);
public static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object self, java.lang.Object[] args)
return method.invoke(self, args);
public static java.lang.Object newInstance(java.lang.Class cls)
return cls.newInstance();
public static java.lang.Object newInstance(java.lang.Class cls, java.lang.Class[] paramTypes, java.lang.Object[] params)
return cls.getConstructor(paramTypes).newInstance(params);
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |