Class TypeUtil
- java.lang.Object
-
- com.oracle.coherence.io.json.genson.reflect.TypeUtil
-
public final class TypeUtil extends Object
This class provides utilities to work with java Types. Its main goal is to provide tools for working with generic types.- Author:
- Eugen Cepoi
-
-
Constructor Summary
Constructors Constructor Description TypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TypeexpandType(Type type, Type rootType)Expands type in the type rootType to Class, ParameterizedType or GenericArrayType.static TypegetCollectionType(Type type)Returns the type of this Collection or Array.static Class<?>getRawClass(Type type)static TypelookupGenericType(Class<?> ofClass, Class<?> inClass)Searches for ofClass in the inherited classes and interfaces of inClass.static booleanmatch(Type type, Type oType, boolean strictMatch)Deep comparison between type and oType.static TyperesolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass)Searches for the typevariable definition in the inClass hierarchy.static TypetypeOf(int parameterIdx, Type fromType)Convenient method that returns the type of the parameter at position parameterIdx in the type fromType.static Class<?>wrap(Class<?> clazz)
-
-
-
Method Detail
-
expandType
public static final Type expandType(Type type, Type rootType)
Expands type in the type rootType to Class, ParameterizedType or GenericArrayType. Useful for generic types. rootType is used to get the specialization information for expansion.
-
lookupGenericType
public static final Type lookupGenericType(Class<?> ofClass, Class<?> inClass)
Searches for ofClass in the inherited classes and interfaces of inClass. If ofClass has been found in the super classes/interfaces of inClass, then the generic type corresponding to inClass and its TypeVariables is returned, otherwise null. For example :abstract class MyClass implements Serializer<Number> { } // type value will be the parameterized type Serializer<Number> Type type = lookupGenericType(Serializer.class, MyClass.class);
-
getCollectionType
public static final Type getCollectionType(Type type)
Returns the type of this Collection or Array.- Throws:
IllegalArgumentException- if type is not a Collection, not a generic array and not a primitive array.
-
resolveTypeVariable
public static final Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass)
Searches for the typevariable definition in the inClass hierarchy.- Parameters:
type-inClass-- Returns:
- the resolved type or type if unable to resolve it.
-
match
public static final boolean match(Type type, Type oType, boolean strictMatch)
Deep comparison between type and oType. If parameter strictMatch is true, then type and oType will be strictly compared otherwise this method checks whether oType is assignable from type.
-
typeOf
public static final Type typeOf(int parameterIdx, Type fromType)
Convenient method that returns the type of the parameter at position parameterIdx in the type fromType.- Throws:
UnsupportedOperationException- thrown if fromType is not a Class nor a ParameterizedType.
-
-