Package com.aspectran.core.util
Class ClassUtils
- java.lang.Object
-
- com.aspectran.core.util.ClassUtils
-
public abstract class ClassUtils extends java.lang.ObjectMiscellaneous class utility methods.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASS_FILE_SUFFIXThe ".class" file suffixstatic charPACKAGE_SEPARATOR_CHARThe package separator character '.'
-
Constructor Summary
Constructors Constructor Description ClassUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TcreateInstance(java.lang.Class<T> cls)Method that can be called to try to create an instantiate of specified type.static <T> TcreateInstance(java.lang.Class<T> cls, java.lang.Object... args)Method that can be called to try to create an instantiate of specified type.static <T> java.lang.reflect.Constructor<T>findConstructor(java.lang.Class<T> cls, java.lang.Class<?>... parameterTypes)Obtain an accessible constructor for the given class and parameters.
-
-
-
Field Detail
-
PACKAGE_SEPARATOR_CHAR
public static final char PACKAGE_SEPARATOR_CHAR
The package separator character '.'- See Also:
- Constant Field Values
-
CLASS_FILE_SUFFIX
public static final java.lang.String CLASS_FILE_SUFFIX
The ".class" file suffix- See Also:
- Constant Field Values
-
-
Method Detail
-
createInstance
public static <T> T createInstance(java.lang.Class<T> cls)
Method that can be called to try to create an instantiate of specified type. Instantiation is done using default no-argument constructor.- Type Parameters:
T- the generic type- Parameters:
cls- the class to check- Returns:
- an instantiated object
- Throws:
java.lang.IllegalArgumentException- if instantiation fails for any reason; except for cases where constructor throws an unchecked exception (which will be passed as is)
-
createInstance
public static <T> T createInstance(java.lang.Class<T> cls, java.lang.Object... args)Method that can be called to try to create an instantiate of specified type.- Type Parameters:
T- the generic type- Parameters:
cls- the class to checkargs- the arguments- Returns:
- an instantiated object
- Throws:
java.lang.IllegalArgumentException- if instantiation fails for any reason; except for cases where constructor throws an unchecked exception (which will be passed as is)
-
findConstructor
public static <T> java.lang.reflect.Constructor<T> findConstructor(java.lang.Class<T> cls, java.lang.Class<?>... parameterTypes) throws java.lang.NoSuchMethodExceptionObtain an accessible constructor for the given class and parameters.- Type Parameters:
T- the generic type- Parameters:
cls- the class to checkparameterTypes- the parameter types of the desired constructor- Returns:
- the constructor reference
- Throws:
java.lang.NoSuchMethodException- if no such constructor exists
-
-