Package org.jvnet.hk2.config.tiger
Class Types
java.lang.Object
org.jvnet.hk2.config.tiger.Types
Type arithmetic functions.
- Author:
- Kohsuke Kawaguchi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ParameterizedTypecreateParameterizedType(Class rawType, Type... arguments) Returns theTypeobject that representsclazz<T1,T2,T3>.static <T> Class<T>Returns theClassrepresentation of the given type.static TypegetBaseClass(Type type, Class baseType) Gets the parameterization of the given base type.static TypeGets the component type of the array.static TypegetTypeArgument(Type type, int i) Gets the i-th type argument from a parameterized type.static TypegetTypeArgument(Type type, int i, Type defaultValue) Gets the i-th type argument from a parameterized type.static StringgetTypeName(Type type) Gets the display name of the type objectstatic booleanChecks if the type is an array type.static booleanChecks if the type is an array type but not byte[].static booleanisOverriding(Method method, Class base) static booleanisPrimitive(Type type) Checks if the given type is a primitive type.static booleanisSubClassOf(Type sub, Type sup) Checks ifsubis a sub-type ofsup.
-
Constructor Details
-
Types
public Types()
-
-
Method Details
-
getBaseClass
Gets the parameterization of the given base type.For example, given the following
This method works like this:interface Foo extends List<List > {} interface Bar extends Foo {} getBaseClass( Bar, List ) = List<List getBaseClass( Bar, Foo ) = Foo getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>> getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger> - Parameters:
type- The type that derives frombaseTypebaseType- The class whose parameterization we are interested in.- Returns:
- The use of
baseTypeintype. or null if the type is not assignable to the base type.
-
getTypeName
Gets the display name of the type object- Returns:
- a human-readable name that the type represents.
-
isSubClassOf
Checks ifsubis a sub-type ofsup. -
erasure
Returns theClassrepresentation of the given type. This corresponds to the notion of the erasure in JSR-14.It made me realize how difficult it is to define the common navigation layer for two different underlying reflection library. The other way is to throw away the entire parameterization and go to the wrapper approach.
-
createParameterizedType
Returns theTypeobject that representsclazz<T1,T2,T3>. -
isArray
Checks if the type is an array type. -
isArrayButNotByteArray
Checks if the type is an array type but not byte[]. -
getComponentType
Gets the component type of the array.- Parameters:
t- must be an array.
-
getTypeArgument
Gets the i-th type argument from a parameterized type.Unlike
getTypeArgument(Type, int, Type), this method throwsIllegalArgumentExceptionif the given type is not parameterized. -
getTypeArgument
Gets the i-th type argument from a parameterized type.For example,
getTypeArgument([Map<Integer,String>],0)=IntegerIf the given type is not a parameterized type, returns the specified default value.This is convenient for handling raw types and parameterized types uniformly.
- Throws:
IndexOutOfBoundsException- If i is out of range.
-
isPrimitive
Checks if the given type is a primitive type. -
isOverriding
-