public class ClassUtils
extends java.lang.Object
| Constructor and Description |
|---|
ClassUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
asClassOrNull(java.lang.Object object,
java.lang.Class<T> requiredClass)
Return object cast to requiredClass.
|
static <T> T |
asClassUnchecked(java.lang.Object object)
Return object cast to T without a check.
|
static <T> T |
asClassUnchecked(java.lang.Object object,
T requiredClassObject)
Return object cast to T without a check.
|
static boolean |
equals(java.lang.Object left,
java.lang.Object right)
Return true if left and right are equal, avoiding an NPE by first using
left==right before attempting left.equals(right).
|
static <T> java.lang.Class<T> |
getClass(T object)
Return the fully typed class of an object.
|
static <T> T |
isInstanceOf(java.lang.Object anObject,
java.lang.Class<T> aClass)
Return anObject cast to aClass if type-safe or null otherwise.
|
public static <T> T asClassOrNull(java.lang.Object object,
java.lang.Class<T> requiredClass)
object - to cast.requiredClass - to cast to.public static <T> T asClassUnchecked(java.lang.Object object,
T requiredClassObject)
This enables type-checking to be suppressed on a single expression term avoiding the need for suppressing unchecked warnings throughout the rest of an invoking method.
Use as: asClassUnchecked(object, (ArbitrarilyComplicatedType)null)
T - required typeobject - to castrequiredClassObject - dummy argument: use nullpublic static <T> T asClassUnchecked(java.lang.Object object)
This enables type-checking to suppressed on a single expression term avoiding the need for suppressing unchecked warnings throughout the rest of an invoking method.
Use as: ArbitrarilyComplicatedType castObject = asClassUnchecked(object);
T - required typeobject - to castpublic static boolean equals(java.lang.Object left,
java.lang.Object right)
left - right - public static <T> java.lang.Class<T> getClass(T object)
T - typeobject - the objectpublic static <T> T isInstanceOf(java.lang.Object anObject,
java.lang.Class<T> aClass)
anObject - for which cast requiredaClass - the type to which cast required