public class GenericTypeResolver extends java.lang.Object
The instances of this class are bound to single classes, for which they are constructed. They only work correctly when querying parameters originating from this class or one of its methods. Furthermore this class does not work, if the class the lookup is performed for is generic itself.
The error handling of this class is rather crude. If any of the assumptions
(either specified above or we learned from playing with reflection) is not
met, an exception is thrown (currently IllegalStateException
).
Constructor and Description |
---|
GenericTypeResolver(java.lang.Class<?> clazz)
Creates a new generic type resolver for the given class.
|
GenericTypeResolver(java.lang.reflect.Field field,
GenericTypeResolver parentResolver)
Creates a new generic type resolver for the given field and resolver of the
field's (non-generic) class or child class.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Class<?> |
resolveGenericType(java.lang.reflect.Type genericType)
Returns the actual type from a (potentially) generic type.
|
public GenericTypeResolver(java.lang.Class<?> clazz)
java.lang.IllegalArgumentException
- if called for generic class.public GenericTypeResolver(java.lang.reflect.Field field, GenericTypeResolver parentResolver)
public java.lang.Class<?> resolveGenericType(java.lang.reflect.Type genericType)
List<String>
the raw type (here: List) is returned.
Note that this only works for return values and parameters of methods belonging to the class for which this instance was constructed for. Otherwise the behavior is undefined (either returning nonsense or throwing an exception).
genericType
- a type such as returned from Method.getGenericReturnType()
or Method.getGenericParameterTypes()
.