public final class ReflectionHelper extends Object
PrivilegedAction
which is necessary
for situations where a security manager is in place.Modifier and Type | Method and Description |
---|---|
static Class<?> |
boxedType(Class<?> type)
Returns the corresponding auto-boxed type if given a primitive type.
|
static Type |
boxedType(Type type)
Returns the corresponding auto-boxed type if given a primitive type.
|
static Class<?> |
getClassFromType(Type type)
Converts the given
Type to a Class . |
static Type |
getCollectionElementType(Type type)
Determines the type of the elements of an
Iterable , array or the value of a Map . |
static Object |
getIndexedValue(Object value,
int index)
Tries to retrieve the indexed value from the specified object.
|
static Object |
getMappedValue(Object value,
Object key)
Tries to retrieve the mapped value from the specified object.
|
static Object |
getValue(Field field,
Object object) |
static Object |
getValue(Method method,
Object object) |
static boolean |
isCollection(Type type)
Indicates whether the given type represents a collection of elements or not (i.e.
|
static boolean |
isIndexable(Type type)
Indicates if the type is considered indexable (ie is a
List , an array or a Map ). |
static boolean |
isIterable(Type type) |
static boolean |
isList(Type type) |
static boolean |
isMap(Type type) |
static Type |
typeOf(Member member) |
static Class<?> |
unBoxedType(Class<?> type)
Returns the primitive type for a boxed type.
|
public static Type typeOf(Member member)
member
- The Member
instance for which to retrieve the type.Type
of the given Field
or Method
.IllegalArgumentException
- in case member
is not a Field
or Method
.public static boolean isCollection(Type type)
Iterable
, Map
or array type).public static Type getCollectionElementType(Type type)
Iterable
, array or the value of a Map
.public static boolean isIndexable(Type type)
List
, an array or a Map
).
Note that it does not include Set
s as they are not indexable.
type
- the type to inspect.public static Class<?> getClassFromType(Type type)
Type
to a Class
.type
- the type to convertpublic static boolean isIterable(Type type)
type
- the type to check.true
if type
is a iterable type, false
otherwise.public static boolean isMap(Type type)
type
- the type to check.true
if type
is implementing Map
, false
otherwise.public static boolean isList(Type type)
type
- the type to check.true
if type
is implementing List
, false
otherwise.public static Object getIndexedValue(Object value, int index)
value
- The object from which to retrieve the indexed value. The object has to be non null
and
either a collection or array.index
- The index.null
if value
is null
or not a collection or array.
null
is also returned in case the index does not exist.public static Object getMappedValue(Object value, Object key)
value
- The object from which to retrieve the mapped value. The object has to be non null
and
must implement the @{code Map} interface.key
- The map key. index.null
if value
is null
or not implementing @{code Map}.public static Type boxedType(Type type)
public static Class<?> boxedType(Class<?> type)
public static Class<?> unBoxedType(Class<?> type)
type
- the boxed typeVoid
is
passed (which is considered as primitive type by
Class.isPrimitive()
), Void
will be returned.IllegalArgumentException
- in case the parameter primitiveType
does not
represent a primitive type.Copyright © 2007-2021 Red Hat, Inc. All Rights Reserved