|
TUM CCSM Commons | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.tum.cs.commons.reflect.GenericTypeResolver
public class GenericTypeResolver
This is a class for helping with the resolution of generic types in the context of reflection. Unfortunately there is no easy way to get the actual return type or parameter type of a method if some generic class is within the class hierarchy. This class handles the messy aspects of this.
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 Summary | |
---|---|
GenericTypeResolver(java.lang.Class<?> clazz)
Creates a new generic type resolver for the given class. |
Method Summary | |
---|---|
java.lang.Class<?> |
resolveGenericType(java.lang.reflect.Type genericType)
Returns the actual type from a (potentially) generic type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GenericTypeResolver(java.lang.Class<?> clazz)
java.lang.IllegalArgumentException
- if called for generic class.Method Detail |
---|
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 behaviour is underfined (either returning nonsense or throwing an exception).
genericType
- a type such as returned from
Method.getGenericReturnType()
or
Method.getGenericParameterTypes()
.
|
TUM CCSM Commons | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |