Class ClassUtils
java.lang.Object
com.thebuzzmedia.exiftool.commons.reflection.ClassUtils
Static Class Utilities.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic MethodHandle
findMethod
(Class<?> klass, String methodName, Class<?> returnType, Class<?>... parameterTypes) Find non static method with given return type parameter types on given class.static MethodHandle
findStaticMethod
(Class<?> klass, String methodName, Class<?> returnType, Class<?>... parameterTypes) Find static method with given return type parameter types on given class.static Object
invoke
(MethodHandle method, Object target, Object... args) Invoke given method.static Object
invokeStatic
(MethodHandle method, Object... args) Invoke given static method.static boolean
Check if given class is available on classpath.static Class<?>
lookupClass
(String klass) Get given class if available on classpath, otherwise throwClassUtils.ReflectionException
.
-
Method Details
-
lookupClass
Get given class if available on classpath, otherwise throwClassUtils.ReflectionException
.- Parameters:
klass
- Class name.- Returns:
- The class instance if available.
- Throws:
ClassUtils.ReflectionException
- If given class is not found in the classpath.
-
findStaticMethod
public static MethodHandle findStaticMethod(Class<?> klass, String methodName, Class<?> returnType, Class<?>... parameterTypes) Find static method with given return type parameter types on given class.- Parameters:
klass
- The class.methodName
- The method name.returnType
- The method return type.parameterTypes
- Parameter types.- Returns:
- The method.
- Throws:
ClassUtils.ReflectionException
- If given method does not exist.ClassUtils.ReflectionException
- If given method is not accessible.
-
findMethod
public static MethodHandle findMethod(Class<?> klass, String methodName, Class<?> returnType, Class<?>... parameterTypes) Find non static method with given return type parameter types on given class.- Parameters:
klass
- The class.methodName
- The method name.returnType
- The method return type.parameterTypes
- Parameter types.- Returns:
- The method.
- Throws:
ClassUtils.ReflectionException
- If given method does not exist.ClassUtils.ReflectionException
- If given method is not accessible.
-
invokeStatic
Invoke given static method.- Parameters:
method
- The method to invoke.args
- Method parameters.- Returns:
- The method result.
- Throws:
ClassUtils.ReflectionException
- If an error occurs while calling method.
-
invoke
Invoke given method.- Parameters:
method
- The method to invoke.target
- The target instance.args
- Method parameters.- Returns:
- The method result.
- Throws:
ClassUtils.ReflectionException
- If an error occurs while calling method.
-
isPresent
Check if given class is available on classpath.- Parameters:
klass
- Class name to check (FQN).- Returns:
- True if class is available, false otherwise.
-