Class ReflectionUtils
This class provides static factory methods that convert standard Java reflection objects
(Class, Method, Field, Constructor) to their corresponding
info wrapper objects (ClassInfo, MethodInfo, FieldInfo, ConstructorInfo).
Features:
- Convenient factory methods - convert reflection objects to info wrappers
- Null-safe - methods handle
null inputs gracefully - Unified API - consistent method naming across all reflection types
Use Cases:
- Converting reflection objects to info wrappers in a consistent way
- Simplifying code that works with both reflection and info objects
- Providing a centralized location for reflection-to-info conversions
Usage:
Null Handling:
All methods in this class handle
See Also:
ClassInfo- Class introspection wrapperMethodInfo- Method introspection wrapperFieldInfo- Field introspection wrapperConstructorInfo- Constructor introspection wrapper- Reflection Package
-
Method Summary
Modifier and TypeMethodDescriptionasEnumClass(Class<?> clazz) Converts a class to an enum class, suppressing rawtypes warnings.static final <T> ClassInfoTyped<T>Returns theClassInfoTypedwrapper for the specified class.static final ClassInfoReturns theClassInfowrapper for the class of the specified object.static final ConstructorInfoinfo(Constructor<?> o) Returns theConstructorInfowrapper for the specified constructor.static final FieldInfoReturns theFieldInfowrapper for the specified field.static final MethodInfoReturns theMethodInfowrapper for the specified method.
-
Method Details
-
info
Returns theClassInfoTypedwrapper for the specified class.- Type Parameters:
T- The class type.- Parameters:
o- The class to wrap. Can benull .- Returns:
- The
ClassInfoTypedwrapper, ornull if the input isnull .
-
info
Returns theConstructorInfowrapper for the specified constructor.- Parameters:
o- The constructor to wrap. Can benull .- Returns:
- The
ConstructorInfowrapper, ornull if the input isnull .
-
info
Returns theFieldInfowrapper for the specified field.- Parameters:
o- The field to wrap. Can benull .- Returns:
- The
FieldInfowrapper, ornull if the input isnull .
-
info
Returns theMethodInfowrapper for the specified method.- Parameters:
o- The method to wrap. Can benull .- Returns:
- The
MethodInfowrapper, ornull if the input isnull .
-
info
Returns theClassInfowrapper for the class of the specified object.- Parameters:
o- The object whose class to wrap. Can benull .- Returns:
- The
ClassInfowrapper for the object's class, ornull if the input isnull .
-
asEnumClass
Converts a class to an enum class, suppressing rawtypes warnings.This utility method wraps
Class.asSubclass(Class)for enum classes and suppresses the rawtypes warning that occurs when converting toClass<? extends Enum>for use with methods likeEnumSet.allOf(Class).Example:
// Instead of: @SuppressWarnings ("rawtypes" ) Class<?extends Enum>enumClass =clazz .asSubclass(Enum.class );// Use: Class<?extends Enum>enumClass = ReflectionUtils.asEnumClass (clazz );- Parameters:
clazz- The class to convert. Must be an enum class. Must not benull .- Returns:
- The enum class as a raw type suitable for use with
EnumSet.allOf(Class). - Throws:
ClassCastException- if the class is not an enum class.
-