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
Modifier and TypeMethodDescriptionReturns a type from given class literal.Returns anArrayType
for the given element type and number of dimensions.Returns aClassType
for the given class declaration.Returns aClassType
for the given binary name, as defined by The Java™ Language Specification; in other words, the class name as returned byClass.getName()
.Returns aPrimitiveType
for the given kind of primitive type.ofVoid()
Returns aVoidType
, representing thevoid
pseudo-type.parameterized
(ClassType genericType, Type... typeArguments) Returns aParameterizedType
for the given generic type and type arguments.parameterized
(Class<?> genericType, Type... typeArguments) Returns aParameterizedType
for the given generic type and type arguments.parameterized
(Class<?> genericType, Class<?>... typeArguments) Returns aParameterizedType
for the given generic type and type arguments.Returns aWildcardType
that represents an equivalent of?
.wildcardWithLowerBound
(Type lowerBound) Returns aWildcardType
that represents an equivalent of? super lowerBound
.wildcardWithUpperBound
(Type upperBound) Returns aWildcardType
that represents an equivalent of? extends upperBound
.
-
Method Details
-
of
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
Returns aPrimitiveType
for the given kind of primitive type.- Parameters:
kind
- the primitive type kind, must not benull
- Returns:
- the
PrimitiveType
, nevernull
-
ofClass
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
Returns aClassType
for the given class declaration. -
ofArray
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
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
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
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
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
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
-