A lightweight Java utility library that provides static helper methods for working with the Java Reflection API. It simplifies common type-inspection tasks — checking whether a type is a primitive, a collection, a boxed wrapper, an enum, and more — so you do not have to write repetitive boilerplate when building frameworks, serializers, or other reflection-heavy code.
<dependency>
<groupId>io.ljunggren</groupId>
<artifactId>reflection-utils</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
All methods are static. Import the class and call directly:
import io.ljunggren.reflectionUtils.ReflectionUtils;
Returns the raw (erased) type of a parameterized type, or null if the type is not parameterized.
Type owner = ReflectionUtils.getOwnerType(type);
Returns true if the given type is a ParameterizedType (e.g., List<String>).
boolean result = ReflectionUtils.isParameterized(type);
Returns all type arguments of a parameterized type as an array. Returns an empty array if the type is not parameterized.
Type[] types = ReflectionUtils.getParameterizedTypes(type);
Returns the single type argument of a parameterized type, or null if there is not exactly one type argument.
Type type = ReflectionUtils.getParameterizedType(type);
Returns the component type of an array type, or null if the type is not an array.
Type componentType = ReflectionUtils.getArrayComponentType(type);
Returns all fields declared on the class and its superclasses, including private fields.
List<Field> fields = ReflectionUtils.getObjectFields(clazz);
Returns true if the type represents a Java primitive (e.g., int, boolean). Parameterized types always return false.
boolean result = ReflectionUtils.isPrimitive(type); boolean result = ReflectionUtils.isPrimitive(clazz);
Returns true if the value or type is assignable from Number.
boolean result = ReflectionUtils.isNumber(t); // instance check boolean result = ReflectionUtils.isNumber(type); // Type overload boolean result = ReflectionUtils.isNumber(clazz); // Class<?> overload
Returns true if the value or type is Integer.
boolean result = ReflectionUtils.isInteger(t); boolean result = ReflectionUtils.isInteger(type); boolean result = ReflectionUtils.isInteger(clazz);
Returns true if the value or type is Double.
boolean result = ReflectionUtils.isDouble(t); boolean result = ReflectionUtils.isDouble(type); boolean result = ReflectionUtils.isDouble(clazz);
Returns true if the value or type is Short.
boolean result = ReflectionUtils.isShort(t); boolean result = ReflectionUtils.isShort(type); boolean result = ReflectionUtils.isShort(clazz);
Returns true if the value or type is Long.
boolean result = ReflectionUtils.isLong(t); boolean result = ReflectionUtils.isLong(type); boolean result = ReflectionUtils.isLong(clazz);
Returns true if the value or type is Float.
boolean result = ReflectionUtils.isFloat(t); boolean result = ReflectionUtils.isFloat(type); boolean result = ReflectionUtils.isFloat(clazz);
Returns true if the value or type is BigDecimal.
boolean result = ReflectionUtils.isBigDecimal(t); boolean result = ReflectionUtils.isBigDecimal(type); boolean result = ReflectionUtils.isBigDecimal(clazz);
Returns true if the value or type is Byte.
boolean result = ReflectionUtils.isByte(t); boolean result = ReflectionUtils.isByte(type); boolean result = ReflectionUtils.isByte(clazz);
Returns true if the value or type is Boolean.
boolean result = ReflectionUtils.isBoolean(t); boolean result = ReflectionUtils.isBoolean(type); boolean result = ReflectionUtils.isBoolean(clazz);
Returns true if the value or type is String.
boolean result = ReflectionUtils.isString(t); boolean result = ReflectionUtils.isString(type); boolean result = ReflectionUtils.isString(clazz);
Returns true if the value or type is an enum.
boolean result = ReflectionUtils.isEnum(t); boolean result = ReflectionUtils.isEnum(type); boolean result = ReflectionUtils.isEnum(clazz);
Returns true if the type is a boxed primitive wrapper (e.g., Integer, Boolean). Determined by the presence of a TYPE field in the java.lang package. Parameterized types and raw primitives always return false.
boolean result = ReflectionUtils.isBoxed(type); boolean result = ReflectionUtils.isBoxed(clazz);
Returns true if the value or type is assignable from List.
boolean result = ReflectionUtils.isList(t); boolean result = ReflectionUtils.isList(type); boolean result = ReflectionUtils.isList(clazz);
Returns true if the value or type is assignable from Map.
boolean result = ReflectionUtils.isMap(t); boolean result = ReflectionUtils.isMap(type); boolean result = ReflectionUtils.isMap(clazz);
Returns true if the value or type is an array.
boolean result = ReflectionUtils.isArray(t); boolean result = ReflectionUtils.isArray(type); boolean result = ReflectionUtils.isArray(clazz);
Returns true if the value or type is assignable from Set.
boolean result = ReflectionUtils.isSet(t); boolean result = ReflectionUtils.isSet(type); boolean result = ReflectionUtils.isSet(clazz);
Returns true if the value or type is assignable from Collection.
boolean result = ReflectionUtils.isCollection(t); boolean result = ReflectionUtils.isCollection(type); boolean result = ReflectionUtils.isCollection(clazz);
Returns true if the value or type is assignable from Iterable.
boolean result = ReflectionUtils.isIterable(t); boolean result = ReflectionUtils.isIterable(type); boolean result = ReflectionUtils.isIterable(clazz);
Returns true if the class declares only a no-argument constructor. Returns false for parameterized types and null inputs.
boolean result = ReflectionUtils.hasNoArgsConstructor(type); boolean result = ReflectionUtils.hasNoArgsConstructor(clazz);
Reads the value of a field from a target object, bypassing access modifiers.
Object value = ReflectionUtils.getFieldValue(field, target);
MIT