public final class ReflectionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static Field |
findField(Class<?> type,
String name) |
static Type |
getBoundaryOfParametrizedType(Type type,
Type assigningType)
Resolves the
Type of the lower, or, if no lower bound is present, the upper bound of a single type argument of a
ParameterizedType . |
static Class<?>[] |
getInstantiableCollectionTypes() |
static <K,T extends Collection<K>> |
instantiateCollectionType(Class<T> collectionType)
Creates an instance with a default capacity.
|
static <K,T extends Collection<K>> |
instantiateCollectionType(Class<T> collectionType,
int length)
Provides an implementation instance for the desired collection type.
|
static boolean |
isInstantiableCollectionType(Class<?> type) |
static Field |
makeAccessible(Field field)
Makes the
accessible only if it is not. |
static Method |
makeAccessible(Method method)
Makes the
accessible only if it is not. |
static List<Method> |
methodsOf(Class<?> type)
All methods of the given type, its super types and interfaces, starting with the methods of
the given type.
|
public static Type getBoundaryOfParametrizedType(Type type, Type assigningType)
Type
of the lower, or, if no lower bound is present, the upper bound of a single type argument of a
ParameterizedType
.
private List<MyModel> myModel -> MyModel. private List<? extends MyModel> myModel -> MyModel. private List<? super MyModel> myModel -> MyModel. private List<T> myModel | T extends MyModel -> MyModel. private Optional<MyModel> myModel -> MyModel.
type
- must not be null
.public static <K,T extends Collection<K>> Collection<K> instantiateCollectionType(Class<T> collectionType, int length)
List
, a suitable list implementation is instantiated.collectionType
- must not be null
.null
. Throws an IllegalStateException
if the collection type is not supported.public static boolean isInstantiableCollectionType(Class<?> type)
type
- must not be null
.instantiateCollectionType(Class)
.public static Class<?>[] getInstantiableCollectionTypes()
assignable from
in order to be
instantiable
.public static <K,T extends Collection<K>> Collection<K> instantiateCollectionType(Class<T> collectionType)
instantiateCollectionType(Class, int)
public static List<Method> methodsOf(Class<?> type)
type
- must not be null
.null
but rather an empty list.public static Field findField(Class<?> type, String name)
type
- must not be null
.name
- must not be null
.declared field
with the given name, or null
public static Field makeAccessible(Field field)
accessible
only if it is not.field
- must not be null
.public static Method makeAccessible(Method method)
accessible
only if it is not.method
- must not be null
.Copyright © 2024. All rights reserved.