| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectorg.apache.commons.lang.ClassUtilspublic class ClassUtilsextends Objectnull inputs as best it can.
Each method documents its behaviour in more detail.
Field Summary | |
static String |
|
static char |
|
static String |
|
static char |
|
Constructor Summary | |
| |
Method Summary | |
static List |
|
static List |
|
static List |
|
static List |
|
static String |
|
static String |
|
static String |
|
static String |
|
static String |
|
static String |
|
static boolean |
|
static boolean |
|
static boolean |
|
static Class |
|
static Class[] |
|
public static final String INNER_CLASS_SEPARATOR
The inner class separator String:"$".
public static final char INNER_CLASS_SEPARATOR_CHAR
The inner class separator character:'$' ==.
- Field Value:
- '$'
public static final String PACKAGE_SEPARATOR
The package separator String:".".
public static final char PACKAGE_SEPARATOR_CHAR
The package separator character:'.' ==.
- Field Value:
- '.'
public ClassUtils()
ClassUtils instances should NOT be constructed in standard programming. Instead, the class should be used asClassUtils.getShortClassName(cls). This constructor is public to permit tools that require a JavaBean instance to operate.
public static List convertClassNamesToClasses(List classNames)
Given aListof class names, this method converts them into classes. A newListis returned. If the class name cannot be found,nullis stored in theList. If the class name in theListisnull,nullis stored in the outputList.
- Parameters:
classNames- the classNames to change
- Returns:
- a
Listof Class objects corresponding to the class names,nullif null input
public static List convertClassesToClassNames(List classes)
Given aListofClassobjects, this method converts them into class names. A newListis returned.nullobjects will be copied into the returned list asnull.
- Parameters:
classes- the classes to change
- Returns:
- a
Listof class names corresponding to the Class objects,nullif null input
public static List getAllInterfaces(Class cls)
Gets aListof all interfaces implemented by the given class and its superclasses. The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up. Then each superclass is considered in the same way. Later duplicates are ignored, so the order is maintained.
- Parameters:
cls- the class to look up, may benull
- Returns:
- the
Listof interfaces in order,nullif null input
public static List getAllSuperclasses(Class cls)
Gets aListof superclasses for the given class.
- Parameters:
cls- the class to look up, may benull
- Returns:
- the
Listof superclasses in order going up from this onenullif null input
public static String getPackageName(Class cls)
Gets the package name of aClass.
- Parameters:
cls- the class to get the package name for, may benull.
- Returns:
- the package name or an empty string
public static String getPackageName(Object object,
String valueIfNull)Gets the package name of anObject.
- Parameters:
object- the class to get the package name for, may be nullvalueIfNull- the value to return if null
- Returns:
- the package name of the object, or the null value
public static String getPackageName(String className)
Gets the package name from aString. The string passed in is assumed to be a class name - it is not checked. If the class is unpackaged, return an empty string.
- Parameters:
className- the className to get the package name for, may benull
- Returns:
- the package name or an empty string
public static String getShortClassName(Class cls)
Gets the class name minus the package name from aClass.
- Parameters:
cls- the class to get the short name for.
- Returns:
- the class name without the package name or an empty string
public static String getShortClassName(Object object,
String valueIfNull)Gets the class name minus the package name for anObject.
- Parameters:
object- the class to get the short name for, may be nullvalueIfNull- the value to return if null
- Returns:
- the class name of the object without the package name, or the null value
public static String getShortClassName(String className)
Gets the class name minus the package name from a String. The string passed in is assumed to be a class name - it is not checked.
- Parameters:
className- the className to get the short name for
- Returns:
- the class name of the class without the package name or an empty string
public static boolean isAssignable(Class cls,
Class toClass)Checks if oneClasscan be assigned to a variable of anotherClass. Unlike theClass.isAssignableFrom(java.lang.Class)method, this method takes into account widenings of primitive classes andnulls. Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.Nullmay be assigned to any reference type. This method will returntrueifnullis passed in and the toClass is non-primitive. Specifically, this method tests whether the type represented by the specifiedClassparameter can be converted to the type represented by thisClassobject via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.
- Parameters:
cls- the Class to check, may be nulltoClass- the Class to try to assign into, returns false if null
- Returns:
trueif assignment possible
public static boolean isAssignable(Class[] classArray,
Class[] toClassArray)Checks if an array of Classes can be assigned to another array of Classes. This method callsisAssignablefor each Class pair in the input arrays. It can be used to check if a set of arguments (the first parameter) are suitably compatible with a set of method parameter types (the second parameter). Unlike theClass.isAssignableFrom(java.lang.Class)method, this method takes into account widenings of primitive classes andnulls. Primitive widenings allow an int to be assigned to along,floatordouble. This method returns the correct result for these cases.Nullmay be assigned to any reference type. This method will returntrueifnullis passed in and the toClass is non-primitive. Specifically, this method tests whether the type represented by the specifiedClassparameter can be converted to the type represented by thisClassobject via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.
- Parameters:
classArray- the array of Classes to check, may benulltoClassArray- the array of Classes to try to assign into, may benull
- Returns:
trueif assignment possible
public static boolean isInnerClass(Class cls)
Is the specified class an inner class or static nested class.
- Parameters:
cls- the class to check, may be null
- Returns:
trueif the class is an inner or static nested class, false if not ornull
public static Class primitiveToWrapper(Class cls)
Converts the specified primitive Class object to its corresponding wrapper Class object.
- Parameters:
cls- the class to convert, may be null
- Returns:
- the wrapper class for
clsorclsifclsis not a primitive.nullif null input.
- Since:
- 2.1
public static Class[] primitivesToWrappers(Class[] classes)
Converts the specified array of primitive Class objects to an array of its corresponding wrapper Class objects.
- Parameters:
classes- the class array to convert, may be null or empty
- Returns:
- an array which contains for each given class, the wrapper class or the original class if class is not a primitive.
nullif null input. Empty array if an empty array passed in.
- Since:
- 2.1