|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jvnet.tiger_types.Types
public class Types
Type arithmetic functions.
Constructor Summary | |
---|---|
Types()
|
Method Summary | ||
---|---|---|
static java.lang.reflect.ParameterizedType |
createParameterizedType(java.lang.Class rawType,
java.lang.reflect.Type... arguments)
Returns the Type object that represents clazz<T1,T2,T3> . |
|
static
|
erasure(java.lang.reflect.Type t)
Returns the Class representation of the given type. |
|
static java.lang.reflect.Type |
getBaseClass(java.lang.reflect.Type type,
java.lang.Class baseType)
Gets the parameterization of the given base type. |
|
static java.lang.reflect.Type |
getComponentType(java.lang.reflect.Type t)
Gets the component type of the array. |
|
static java.lang.reflect.Type |
getTypeArgument(java.lang.reflect.Type type,
int i)
Gets the i-th type argument from a parameterized type. |
|
static java.lang.reflect.Type |
getTypeArgument(java.lang.reflect.Type type,
int i,
java.lang.reflect.Type defaultValue)
Gets the i-th type argument from a parameterized type. |
|
static java.lang.String |
getTypeName(java.lang.reflect.Type type)
Gets the display name of the type object |
|
static boolean |
isArray(java.lang.reflect.Type t)
Checks if the type is an array type. |
|
static boolean |
isArrayButNotByteArray(java.lang.reflect.Type t)
Checks if the type is an array type but not byte[]. |
|
static boolean |
isOverriding(java.lang.reflect.Method method,
java.lang.Class base)
|
|
static boolean |
isPrimitive(java.lang.reflect.Type type)
Checks if the given type is a primitive type. |
|
static boolean |
isSubClassOf(java.lang.reflect.Type sub,
java.lang.reflect.Type sup)
Checks if sub is a sub-type of sup . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Types()
Method Detail |
---|
public static java.lang.reflect.Type getBaseClass(java.lang.reflect.Type type, java.lang.Class baseType)
For example, given the following
This method works like this:interface Foo extends List > {} interface Bar extends Foo
{}
getBaseClass( Bar, List ) = List getBaseClass( Bar, Foo ) = Foo
getBaseClass( Foo extends Number>, Collection ) = Collection > getBaseClass( ArrayList extends BigInteger>, List ) = List extends BigInteger>
type
- The type that derives from baseType
baseType
- The class whose parameterization we are interested in.
baseType
in type
.
or null if the type is not assignable to the base type.public static java.lang.String getTypeName(java.lang.reflect.Type type)
public static boolean isSubClassOf(java.lang.reflect.Type sub, java.lang.reflect.Type sup)
sub
is a sub-type of sup
.
public static <T> java.lang.Class<T> erasure(java.lang.reflect.Type t)
Class
representation 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.
public static java.lang.reflect.ParameterizedType createParameterizedType(java.lang.Class rawType, java.lang.reflect.Type... arguments)
Type
object that represents clazz<T1,T2,T3>
.
public static boolean isArray(java.lang.reflect.Type t)
public static boolean isArrayButNotByteArray(java.lang.reflect.Type t)
public static java.lang.reflect.Type getComponentType(java.lang.reflect.Type t)
t
- must be an array.public static java.lang.reflect.Type getTypeArgument(java.lang.reflect.Type type, int i)
Unlike getTypeArgument(Type, int, Type)
, this method
throws IllegalArgumentException
if the given type is
not parameterized.
public static java.lang.reflect.Type getTypeArgument(java.lang.reflect.Type type, int i, java.lang.reflect.Type defaultValue)
For example, getTypeArgument([Map<Integer,String>],0)=Integer
If the given type is not a parameterized type, returns the specified
default value.
This is convenient for handling raw types and parameterized types uniformly.
java.lang.IndexOutOfBoundsException
- If i is out of range.public static boolean isPrimitive(java.lang.reflect.Type type)
public static boolean isOverriding(java.lang.reflect.Method method, java.lang.Class base)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |