org.jopendocument.util
Class ReflectUtils
java.lang.Object
org.jopendocument.util.ReflectUtils
public final class ReflectUtils
- extends Object
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReflectUtils
public ReflectUtils()
getTypeArgumentsMap
public static <T> Map<TypeVariable<Class<T>>,Class<?>> getTypeArgumentsMap(Class<? extends T> childClass,
Class<T> baseClass)
- The map of type arguments of baseClass to actual type for childClass.
- Type Parameters:
T
- the type of the baseClass.- Parameters:
childClass
- the class to test, eg Props.class with Props extends Map.baseClass
- the generic superclass, eg Map.class.
- Returns:
- a the map, eg {K => String.class, V => null}.
getTypeArguments
public static <T> List<Class<?>> getTypeArguments(Class<? extends T> childClass,
Class<T> baseClass)
- Search for the list of class used to extend/implement a generic class/interface.
- Type Parameters:
T
- the type of the baseClass.- Parameters:
childClass
- the class to test, eg Props.class with Props extends Map.baseClass
- the generic superclass, eg Map.class.
- Returns:
- the list of actual classes w/o the possible nulls (if childClass is generic), never
null
, eg [Boolean.class].
getTypeArguments
public static <U> List<Class<?>> getTypeArguments(U o,
Class<U> raw)
isCastable
public static <U> boolean isCastable(U o,
Class<U> raw,
Class... typeArgs)
- Whether o can be casted to raw<typeArgs>.
- Type Parameters:
U
- type of the superclass.- Parameters:
o
- the instance to check, eg new MapOfInt2Boolean().raw
- the generic superclass, eg Map.class.typeArgs
- arguments to raw
, eg Integer.class, Boolean.class.
- Returns:
- whether o is a raw<typeArgs>, eg
true
: new MapOfInt2Boolean()
is a Map<Integer, Boolean>.
Copyright © 2010 jOpenDocument All Rights Reserved.