public class ClassUtils extends Object
| Constructor and Description |
|---|
ClassUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
cast(Class<T> ignored,
Object object)
Cast an Object to the type including primitive types.
|
static Class<?>[] |
classesFor(String[] classNames,
ClassLoader loader)
String array to class array.
|
static String[] |
classesToStrings(Class<?>[] classes)
Convenience method to convert and array of classes to an array of strings.
|
static Class<?> |
classFor(String className,
ClassLoader loader)
Same as
Class.forName(java.lang.String) except that exception logs the class loader stack before
crashing. |
static Class<?> |
getComponentTypeOfParameter(Method method,
int parameterNumber) |
static String |
getSimpleName(Class<?> cl)
Try and work out the simple name from anonymous classes and the like.
|
static Object |
instantiate(String className,
ClassLoader loader)
Instantiates a Class but converts the exception if it fails.
|
static Class<?> |
primitiveTypeForName(String className)
Provide the primitive class for the name.
|
static Class<?> |
primitiveTypeForWrapper(Class<?> wrapperType)
Provide the primitive type for a wrapper class.
|
static Class<?> |
rawType(Type type)
Return the Raw type of a Type which is either already a raw type or a Parameterised type such as
List<String> which would be List.
|
static Class<?> |
wrapperClassForPrimitive(Class<?> primitiveType)
Provide the wrapper class for a primitive type.
|
public static Class<?> primitiveTypeForName(String className)
className - The class name.public static Class<?> wrapperClassForPrimitive(Class<?> primitiveType)
primitiveType - public static Class<?> primitiveTypeForWrapper(Class<?> wrapperType)
wrapperType - public static Class<?> classFor(String className, ClassLoader loader) throws ClassNotFoundException
Class.forName(java.lang.String) except that exception logs the class loader stack before
crashing.className - loader - ClassNotFoundExceptionpublic static Class<?>[] classesFor(String[] classNames, ClassLoader loader) throws ClassNotFoundException
classNames - The class names.loader - The classloader to use.ClassNotFoundException - If a class isn't found.public static String[] classesToStrings(Class<?>[] classes)
classes - The class array.public static Object instantiate(String className, ClassLoader loader) throws ArooaException
className - loader - ArooaExceptionpublic static <T> T cast(Class<T> ignored, Object object)
Class.cast(Object) method
won't cope with primitive type casting it's wrapper. This simple little bodge gets round that.T - The type.ignored - The class which may be primitive. For type inference only.object - The object wrapper.public static String getSimpleName(Class<?> cl)
cl - public static Class<?> rawType(Type type) throws IllegalArgumentException
type - The type which may be generic or not.IllegalArgumentException - if the type is not a Class or Parameterised Type.Copyright © 2023. All rights reserved.