Interface Types
-
public interface Types
Factory for types. Allows creating representations of the void pseudo-type, primitive types, class types, array types, parameterized types and wildcard types.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Type
of(Class<?> clazz)
Returns a type from given class literal.ArrayType
ofArray(Type elementType, int dimensions)
Returns anArrayType
for the given element type and number of dimensions.ClassType
ofClass(ClassInfo clazz)
Returns aClassType
for the given class declaration.ClassType
ofClass(String name)
Returns aClassType
for the given binary name, as defined by The Java™ Language Specification; in other words, the class name as returned byClass.getName()
.PrimitiveType
ofPrimitive(PrimitiveType.PrimitiveKind kind)
Returns aPrimitiveType
for the given kind of primitive type.VoidType
ofVoid()
Returns aVoidType
, representing thevoid
pseudo-type.ParameterizedType
parameterized(ClassType genericType, Type... typeArguments)
Returns aParameterizedType
for the given generic type and type arguments.ParameterizedType
parameterized(Class<?> genericType, Type... typeArguments)
Returns aParameterizedType
for the given generic type and type arguments.ParameterizedType
parameterized(Class<?> genericType, Class<?>... typeArguments)
Returns aParameterizedType
for the given generic type and type arguments.WildcardType
wildcardUnbounded()
Returns aWildcardType
that represents an equivalent of?
.WildcardType
wildcardWithLowerBound(Type lowerBound)
Returns aWildcardType
that represents an equivalent of? super lowerBound
.WildcardType
wildcardWithUpperBound(Type upperBound)
Returns aWildcardType
that represents an equivalent of? extends upperBound
.
-
-
-
Method Detail
-
of
Type of(Class<?> clazz)
Returns a type from given class literal. For example:of(void.class)
: same asofVoid
()
of(int.class)
: same asofPrimitive
(PrimitiveKind.INT)
of(String.class)
: same asofClass
(... ClassInfo for String ...)
of(int[].class)
: same asofArray
(ofPrimitive(PrimitiveKind.INT), 1)
of(String[][].class)
: same asofArray(ofClass(... ClassInfo for String ...), 2)
- Parameters:
clazz
- the class literal, must not benull
- Returns:
Type
object representing the given class literal
-
ofVoid
VoidType ofVoid()
Returns aVoidType
, representing thevoid
pseudo-type.- Returns:
- the
VoidType
, nevernull
-
ofPrimitive
PrimitiveType ofPrimitive(PrimitiveType.PrimitiveKind kind)
Returns aPrimitiveType
for the given kind of primitive type.- Parameters:
kind
- the primitive type kind, must not benull
- Returns:
- the
PrimitiveType
, nevernull
-
ofClass
ClassType ofClass(String name)
Returns aClassType
for the given binary name, as defined by The Java™ Language Specification; in other words, the class name as returned byClass.getName()
.Note that this method returns
ClassType
, soname
may only be a name of a class. For primitives, useofPrimitive(PrimitiveType.PrimitiveKind)
. For arrays, useofArray(Type, int)
.- Parameters:
name
- the binary name of the class, must not benull
- Returns:
- the
ClassType
ornull
if the class is not present in any bean archive
-
ofClass
ClassType ofClass(ClassInfo clazz)
Returns aClassType
for the given class declaration.
-
ofArray
ArrayType ofArray(Type elementType, int dimensions)
Returns anArrayType
for the given element type and number of dimensions.Note that this method accepts the element type of an array, even though
ArrayType
uses a component type representation. For example, the component type ofString[][]
isString[]
, while the element type isString
.- Parameters:
elementType
- the elementType
, must not benull
dimensions
- the number of dimensions- Returns:
- the
ArrayType
, nevernull
- Throws:
IllegalArgumentException
- if the element type is an array type, a wildcard type, or the void pseudo-type
-
parameterized
ParameterizedType parameterized(Class<?> genericType, Class<?>... typeArguments)
Returns aParameterizedType
for the given generic type and type arguments. The array of type arguments must have the same shape as the generic type's list of type parameters.- Parameters:
genericType
- the type to parameterize, must not benull
typeArguments
- one or more type arguments- Returns:
- the parameterized type, never
null
- Throws:
IllegalArgumentException
- if givengenericType
is not generic or if the number of type arguments does not match the number of type parameters declared bygenericType
-
parameterized
ParameterizedType parameterized(Class<?> genericType, Type... typeArguments)
Returns aParameterizedType
for the given generic type and type arguments. The array of type arguments must have the same shape as the generic type's list of type parameters.- Parameters:
genericType
- the type to parameterize, must not benull
typeArguments
- one or more type arguments- Returns:
- the parameterized type, never
null
- Throws:
IllegalArgumentException
- if givengenericType
is not generic or if the number of type arguments does not match the number of type parameters declared bygenericType
-
parameterized
ParameterizedType parameterized(ClassType genericType, Type... typeArguments)
Returns aParameterizedType
for the given generic type and type arguments. The array of type arguments must have the same shape as the generic type's list of type parameters.- Parameters:
genericType
- the type to parameterize, must not benull
typeArguments
- one or more type arguments- Returns:
- the parameterized type, never
null
- Throws:
IllegalArgumentException
- if givengenericType
is not generic or if the number of type arguments does not match the number of type parameters declared bygenericType
-
wildcardWithUpperBound
WildcardType wildcardWithUpperBound(Type upperBound)
Returns aWildcardType
that represents an equivalent of? extends upperBound
. Note that ifupperBound
represents thejava.lang.Object
type, then the result is equivalent towildcardUnbounded()
.- Parameters:
upperBound
- upper bound type, must not benull
- Returns:
- a
WildcardType
object representing a wildcard type with given upper bound
-
wildcardWithLowerBound
WildcardType wildcardWithLowerBound(Type lowerBound)
Returns aWildcardType
that represents an equivalent of? super lowerBound
.- Parameters:
lowerBound
- lower bound type, must not benull
- Returns:
- a
WildcardType
object representing a wildcard type with given upper bound
-
wildcardUnbounded
WildcardType wildcardUnbounded()
Returns aWildcardType
that represents an equivalent of?
.- Returns:
- a
WildcardType
object representing an unbounded wildcard type
-
-