Package com.github.toolarium.common.util
Class ReflectionUtil
- java.lang.Object
-
- com.github.toolarium.common.util.ReflectionUtil
-
public final class ReflectionUtil extends java.lang.ObjectDefines the reflection utility.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.lang.ObjectcallMethod(java.lang.Object classInstance, java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] paramType, java.lang.Object[] param)Calls the given method on the given instancevoiddisableAccessWarnings()Disable access warnings<T> java.lang.Class<T>getClassObject(java.lang.String className)Load a class by given namestatic ReflectionUtilgetInstance()Get the instance<T> java.lang.reflect.MethodgetMethod(java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] paramType)Gets the defined method backbooleanisClassAvailable(java.lang.String className)Check if the given class exists<T> TnewInstance(java.lang.Class<T> clazz)Create a new instance of a given class
-
-
-
Method Detail
-
getInstance
public static ReflectionUtil getInstance()
Get the instance- Returns:
- the instance
-
isClassAvailable
public boolean isClassAvailable(java.lang.String className) throws java.lang.IllegalArgumentExceptionCheck if the given class exists- Parameters:
className- the name of the class to check- Returns:
- true if the class exists; otherwise false
- Throws:
java.lang.IllegalArgumentException- In case of an invalid class name
-
getClassObject
public <T> java.lang.Class<T> getClassObject(java.lang.String className) throws java.lang.IllegalArgumentException, java.lang.ClassNotFoundExceptionLoad a class by given name- Type Parameters:
T- the generic type- Parameters:
className- the name of the class- Returns:
- the loaded class
- Throws:
java.lang.IllegalArgumentException- In case of an invalid class namejava.lang.ClassNotFoundException- in case of error
-
newInstance
public <T> T newInstance(java.lang.Class<T> clazz) throws java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.InstantiationException, java.lang.IllegalAccessExceptionCreate a new instance of a given class- Type Parameters:
T- the generic type- Parameters:
clazz- the class- Returns:
- the instance
- Throws:
java.lang.IllegalArgumentException- In case of an invalid class namejava.lang.SecurityException- in case of errorjava.lang.reflect.InvocationTargetException- in case of errorjava.lang.IllegalArgumentException- in case of errorjava.lang.IllegalAccessException- in case of errorjava.lang.InstantiationException- in case of error
-
getMethod
public <T> java.lang.reflect.Method getMethod(java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] paramType) throws java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.ClassNotFoundExceptionGets the defined method back- Type Parameters:
T- the generic type- Parameters:
className- the class namemethodName- the method nameparamType- the parameter type- Returns:
- the method
- Throws:
java.lang.IllegalArgumentException- In case of an invalid class or method namejava.lang.SecurityException- in case of errorjava.lang.NoSuchMethodException- in case of errorjava.lang.ClassNotFoundException- in case of error
-
callMethod
public <T> java.lang.Object callMethod(java.lang.Object classInstance, java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] paramType, java.lang.Object[] param) throws java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundExceptionCalls the given method on the given instance- Type Parameters:
T- the generic type- Parameters:
classInstance- the instance of the class where the method should be calledclassName- the name of the classmethodName- the method nameparamType- the parameter typeparam- the parameter values- Returns:
- the result
- Throws:
java.lang.SecurityException- in case of errorjava.lang.NoSuchMethodException- in case of errorjava.lang.reflect.InvocationTargetException- in case of errorjava.lang.IllegalAccessException- in case of errorjava.lang.IllegalArgumentException- in case of errorjava.lang.ClassNotFoundException- in case of error
-
disableAccessWarnings
public void disableAccessWarnings()
Disable access warnings
-
-