|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ehcache.internal.classes.commonslang.ClassUtils
public class ClassUtils
Operates on classes without using reflection.
This class handles invalid null
inputs as best it can.
Each method documents its behaviour in more detail.
The notion of a canonical name
includes the human
readable name for the type, for example int[]
. The
non-canonical method variants work with the JVM names, such as
[I
.
Constructor Summary | |
---|---|
ClassUtils()
ClassUtils instances should NOT be constructed in standard programming. |
Method Summary | |
---|---|
static boolean |
isAssignable(java.lang.Class<?>[] classArray,
java.lang.Class<?>[] toClassArray,
boolean autoboxing)
Checks if an array of Classes can be assigned to another array of Classes. |
static boolean |
isAssignable(java.lang.Class<?> cls,
java.lang.Class<?> toClass)
Checks if one Class can be assigned to a variable of
another Class . |
static boolean |
isAssignable(java.lang.Class<?> cls,
java.lang.Class<?> toClass,
boolean autoboxing)
Checks if one Class can be assigned to a variable of
another Class . |
static java.lang.Class<?> |
primitiveToWrapper(java.lang.Class<?> cls)
Converts the specified primitive Class object to its corresponding wrapper Class object. |
static java.lang.Class<?>[] |
toClass(java.lang.Object... array)
Converts an array of Object in to an array of Class objects. |
static java.lang.Class<?> |
wrapperToPrimitive(java.lang.Class<?> cls)
Converts the specified wrapper class to its corresponding primitive class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ClassUtils()
ClassUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as
ClassUtils.getShortClassName(cls)
.
This constructor is public to permit tools that require a JavaBean instance to operate.
Method Detail |
---|
public static boolean isAssignable(java.lang.Class<?>[] classArray, java.lang.Class<?>[] toClassArray, boolean autoboxing)
Checks if an array of Classes can be assigned to another array of Classes.
This method calls isAssignable
for 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 the Class.isAssignableFrom(java.lang.Class)
method, this
method takes into account widenings of primitive classes and
null
s.
Primitive widenings allow an int to be assigned to a long
,
float
or double
. This method returns the correct
result for these cases.
Null
may be assigned to any reference type. This method will
return true
if null
is passed in and the toClass is
non-primitive.
Specifically, this method tests whether the type represented by the
specified Class
parameter can be converted to the type
represented by this Class
object 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.
classArray
- the array of Classes to check, may be null
toClassArray
- the array of Classes to try to assign into, may be null
autoboxing
- whether to use implicit autoboxing/unboxing between primitives and wrappers
true
if assignment possiblepublic static boolean isAssignable(java.lang.Class<?> cls, java.lang.Class<?> toClass)
Checks if one Class
can be assigned to a variable of
another Class
.
Unlike the Class.isAssignableFrom(java.lang.Class)
method,
this method takes into account widenings of primitive classes and
null
s.
Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.
Null
may be assigned to any reference type. This method
will return true
if null
is passed in and the
toClass is non-primitive.
Specifically, this method tests whether the type represented by the
specified Class
parameter can be converted to the type
represented by this Class
object 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.
Since Lang 3.0, this method will default behavior for calculating assignability between primitive and wrapper types corresponding to the running Java version; i.e. autoboxing will be the default behavior in VMs running Java versions > 1.5.
cls
- the Class to check, may be nulltoClass
- the Class to try to assign into, returns false if null
true
if assignment possiblepublic static boolean isAssignable(java.lang.Class<?> cls, java.lang.Class<?> toClass, boolean autoboxing)
Checks if one Class
can be assigned to a variable of
another Class
.
Unlike the Class.isAssignableFrom(java.lang.Class)
method,
this method takes into account widenings of primitive classes and
null
s.
Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.
Null
may be assigned to any reference type. This method
will return true
if null
is passed in and the
toClass is non-primitive.
Specifically, this method tests whether the type represented by the
specified Class
parameter can be converted to the type
represented by this Class
object 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.
cls
- the Class to check, may be nulltoClass
- the Class to try to assign into, returns false if nullautoboxing
- whether to use implicit autoboxing/unboxing between primitives and wrappers
true
if assignment possiblepublic static java.lang.Class<?> primitiveToWrapper(java.lang.Class<?> cls)
Converts the specified primitive Class object to its corresponding wrapper Class object.
NOTE: From v2.2, this method handles Void.TYPE
,
returning Void.TYPE
.
cls
- the class to convert, may be null
cls
or cls
if
cls
is not a primitive. null
if null input.public static java.lang.Class<?> wrapperToPrimitive(java.lang.Class<?> cls)
Converts the specified wrapper class to its corresponding primitive class.
This method is the counter part of primitiveToWrapper()
.
If the passed in class is a wrapper class for a primitive type, this
primitive type will be returned (e.g. Integer.TYPE
for
Integer.class
). For other classes, or if the parameter is
null, the return value is null.
cls
- the class to convert, may be null
cls
is a
wrapper class, null otherwiseprimitiveToWrapper(Class)
public static java.lang.Class<?>[] toClass(java.lang.Object... array)
Converts an array of Object
in to an array of Class
objects.
If any of these objects is null, a null element will be inserted into the array.
This method returns null
for a null
input array.
array
- an Object
array
Class
array, null
if null array input
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |