public class ReflectionUtils extends Object
| Constructor and Description |
|---|
ReflectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Class<?> |
getClass(String clazzName) |
static Option<Method> |
getMethod(Class<?> clazz,
String methodName,
Class<?>... parametersType)
Gets a method based on the method name and type of parameters through reflection.
|
static Stream<String> |
getTopLevelClassesInClasspath(Class<?> clazz)
Scans all classes accessible from the context class loader
which belong to the given package and subpackages.
|
static boolean |
hasConstructor(String clazz,
Class<?>[] constructorArgTypes)
Check if the clazz has the target constructor or not, without throwing warn-level log.
|
static boolean |
hasConstructor(String clazz,
Class<?>[] constructorArgTypes,
boolean silenceWarning)
Check if the clazz has the target constructor or not.
|
static Object |
invokeStaticMethod(String clazz,
String methodName,
Object[] args,
Class<?>... parametersType)
Invoke a static method of a class.
|
static boolean |
isSubClass(String aClazzName,
Class<?> superClazz)
Checks if the given class with the name is a subclass of another class.
|
static <T> T |
loadClass(String className) |
static Object |
loadClass(String clazz,
Class<?>[] constructorArgTypes,
Object... constructorArgs)
Creates an instance of the given class.
|
static Object |
loadClass(String clazz,
Object... constructorArgs)
Creates an instance of the given class.
|
public static <T> T loadClass(String className)
public static Object loadClass(String clazz, Class<?>[] constructorArgTypes, Object... constructorArgs)
public static boolean hasConstructor(String clazz, Class<?>[] constructorArgTypes)
clazz - Class name.constructorArgTypes - Argument types of the constructor.public static boolean hasConstructor(String clazz, Class<?>[] constructorArgTypes, boolean silenceWarning)
When catch HoodieException from loadClass(java.lang.String), it's inconvenient to say if the exception was thrown
due to the instantiation's own logic or missing constructor.
TODO: ReflectionUtils should throw a specific exception to indicate Reflection problem.
clazz - Class name.constructorArgTypes - Argument types of the constructor.silenceWarning - true to use debug-level logging; otherwise, use warn-level logging.true if the constructor exists; false otherwise.public static Object loadClass(String clazz, Object... constructorArgs)
public static Stream<String> getTopLevelClassesInClasspath(Class<?> clazz)
clazz - classpublic static Object invokeStaticMethod(String clazz, String methodName, Object[] args, Class<?>... parametersType)
clazz - methodName - args - parametersType - public static Option<Method> getMethod(Class<?> clazz, String methodName, Class<?>... parametersType)
public static boolean isSubClass(String aClazzName, Class<?> superClazz)
aClazzName - Class name.superClazz - Super class to check.true if aClazzName is a subclass of superClazz;
false otherwise.Copyright © 2025 The Apache Software Foundation. All rights reserved.