org.jopendocument.util
Class ReflectUtils
java.lang.Object
org.jopendocument.util.ReflectUtils
public final class ReflectUtils
- extends java.lang.Object
Method Summary |
static
<T> java.util.List<java.lang.Class<?>> |
|
getTypeArguments(java.lang.Class<? extends T> childClass,
java.lang.Class<T> baseClass)
Search for the list of class used to extend/implement a generic class/interface. |
static
<U> java.util.List<java.lang.Class<?>> |
|
getTypeArguments(U o,
java.lang.Class<U> raw)
|
static
<T> java.util.Map<java.lang.reflect.TypeVariable<java.lang.Class<T>>,java.lang.Class<?>> |
|
getTypeArgumentsMap(java.lang.Class<? extends T> childClass,
java.lang.Class<T> baseClass)
The map of type arguments of baseClass to actual type for childClass. |
static
|
isCastable(U o,
java.lang.Class<U> raw,
java.lang.Class... typeArgs)
Whether o can be casted to raw<typeArgs>. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReflectUtils
public ReflectUtils()
getTypeArgumentsMap
public static <T> java.util.Map<java.lang.reflect.TypeVariable<java.lang.Class<T>>,java.lang.Class<?>> getTypeArgumentsMap(java.lang.Class<? extends T> childClass,
java.lang.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> java.util.List<java.lang.Class<?>> getTypeArguments(java.lang.Class<? extends T> childClass,
java.lang.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> java.util.List<java.lang.Class<?>> getTypeArguments(U o,
java.lang.Class<U> raw)
isCastable
public static <U> boolean isCastable(U o,
java.lang.Class<U> raw,
java.lang.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>.