Package com.github.toolarium.common.util
Class ClassInstanceUtil
java.lang.Object
com.github.toolarium.common.util.ClassInstanceUtil
-
Method Summary
Modifier and TypeMethodDescription<T> T[]createArray(Class<T> theClass, int length) Load a class by given name<T> Class<T> getClassObject(String className) Load a class by given namestatic ClassInstanceUtilGet the instancebooleanimplementsInterface(String className, Class<?> interfaceClazz) Check if a given class implements an interfacebooleanisClassAvailable(String className) Check if the given class exists<T> TnewInstance(Class<T> clazz) Create a new instance of a given class<T> TnewInstance(String className) Create a new instance of a given class
-
Method Details
-
getInstance
Get the instance- Returns:
- the instance
-
getClassObject
Load a class by given name- Type Parameters:
T- the generic type- Parameters:
className- the name of the class- Returns:
- the loaded class
- Throws:
ClassNotFoundException- in case of error
-
newInstance
public <T> T newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException Create a new instance of a given class- Type Parameters:
T- the generic type- Parameters:
className- the name of the class- Returns:
- the loaded class
- Throws:
ClassNotFoundException- in case of errorInstantiationException- in case of errorIllegalAccessException- in case of errorSecurityException- in case of error
-
newInstance
public <T> T newInstance(Class<T> clazz) throws SecurityException, InstantiationException, IllegalAccessException Create a new instance of a given class- Type Parameters:
T- the generic type- Parameters:
clazz- the class- Returns:
- the instance
- Throws:
SecurityException- in case of errorInvocationTargetException- in case of errorIllegalArgumentException- in case of errorIllegalAccessException- in case of errorInstantiationException- in case of error
-
createArray
Load a class by given name- Type Parameters:
T- the generic type- Parameters:
theClass- the classlength- the length of the array- Returns:
- the loaded class
- Throws:
IllegalArgumentException- In case of invalid input
-
isClassAvailable
Check if the given class exists- Parameters:
className- the name of the class to check- Returns:
- true if the class exists; otherwise false
-
implementsInterface
Check if a given class implements an interface- Parameters:
className- the class nameinterfaceClazz- the interface- Returns:
- true if the class implements the interface
-