Interface Types
-
public interface TypesFactory 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 Typeof(Class<?> clazz)Returns a type from given class literal.ArrayTypeofArray(Type elementType, int dimensions)Returns anArrayTypefor the given element type and number of dimensions.ClassTypeofClass(ClassInfo clazz)Returns aClassTypefor the given class declaration.ClassTypeofClass(String name)Returns aClassTypefor the given binary name, as defined by The Java™ Language Specification; in other words, the class name as returned byClass.getName().PrimitiveTypeofPrimitive(PrimitiveType.PrimitiveKind kind)Returns aPrimitiveTypefor the given kind of primitive type.VoidTypeofVoid()Returns aVoidType, representing thevoidpseudo-type.ParameterizedTypeparameterized(ClassType genericType, Type... typeArguments)Returns aParameterizedTypefor the given generic type and type arguments.ParameterizedTypeparameterized(Class<?> genericType, Type... typeArguments)Returns aParameterizedTypefor the given generic type and type arguments.ParameterizedTypeparameterized(Class<?> genericType, Class<?>... typeArguments)Returns aParameterizedTypefor the given generic type and type arguments.WildcardTypewildcardUnbounded()Returns aWildcardTypethat represents an equivalent of?.WildcardTypewildcardWithLowerBound(Type lowerBound)Returns aWildcardTypethat represents an equivalent of? super lowerBound.WildcardTypewildcardWithUpperBound(Type upperBound)Returns aWildcardTypethat 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:
Typeobject representing the given class literal
-
ofVoid
VoidType ofVoid()
Returns aVoidType, representing thevoidpseudo-type.- Returns:
- the
VoidType, nevernull
-
ofPrimitive
PrimitiveType ofPrimitive(PrimitiveType.PrimitiveKind kind)
Returns aPrimitiveTypefor 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 aClassTypefor 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, sonamemay 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
ClassTypeornullif the class is not present in any bean archive
-
ofClass
ClassType ofClass(ClassInfo clazz)
Returns aClassTypefor the given class declaration.
-
ofArray
ArrayType ofArray(Type elementType, int dimensions)
Returns anArrayTypefor the given element type and number of dimensions.Note that this method accepts the element type of an array, even though
ArrayTypeuses a component type representation. For example, the component type ofString[][]isString[], while the element type isString.- Parameters:
elementType- the elementType, must not benulldimensions- 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 aParameterizedTypefor 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 benulltypeArguments- one or more type arguments- Returns:
- the parameterized type, never
null - Throws:
IllegalArgumentException- if givengenericTypeis 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 aParameterizedTypefor 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 benulltypeArguments- one or more type arguments- Returns:
- the parameterized type, never
null - Throws:
IllegalArgumentException- if givengenericTypeis 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 aParameterizedTypefor 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 benulltypeArguments- one or more type arguments- Returns:
- the parameterized type, never
null - Throws:
IllegalArgumentException- if givengenericTypeis 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 aWildcardTypethat represents an equivalent of? extends upperBound. Note that ifupperBoundrepresents thejava.lang.Objecttype, then the result is equivalent towildcardUnbounded().- Parameters:
upperBound- upper bound type, must not benull- Returns:
- a
WildcardTypeobject representing a wildcard type with given upper bound
-
wildcardWithLowerBound
WildcardType wildcardWithLowerBound(Type lowerBound)
Returns aWildcardTypethat represents an equivalent of? super lowerBound.- Parameters:
lowerBound- lower bound type, must not benull- Returns:
- a
WildcardTypeobject representing a wildcard type with given upper bound
-
wildcardUnbounded
WildcardType wildcardUnbounded()
Returns aWildcardTypethat represents an equivalent of?.- Returns:
- a
WildcardTypeobject representing an unbounded wildcard type
-
-