public abstract class Type extends Object
A type usage may have annotations associated with its declaration. A type is equal to another type if, and only if, it represents the same exact definition including the annotations specific to its usage.
To reduce memory overhead, type instances are often shared between their enclosing classes.
| Modifier and Type | Class and Description |
|---|---|
static class |
Type.Kind
Represents a "kind" of Type.
|
| Modifier and Type | Field and Description |
|---|---|
static Type[] |
EMPTY_ARRAY |
| Modifier and Type | Method and Description |
|---|---|
List<AnnotationInstance> |
annotations()
Returns the list of annotations declared on this type's usage.
|
ArrayType |
asArrayType()
Casts this type to an
ArrayType and returns it if the kind is
Type.Kind.ARRAY
Throws an exception otherwise. |
ClassType |
asClassType()
Casts this type to a
ClassType and returns it if the kind is Type.Kind.CLASS
Throws an exception otherwise. |
ParameterizedType |
asParameterizedType()
Casts this type to a
ParameterizedType and returns it if the kind is
Type.Kind.PARAMETERIZED_TYPE
Throws an exception otherwise. |
PrimitiveType |
asPrimitiveType()
Casts this type to a
PrimitiveType and returns it if the kind is
Type.Kind.PRIMITIVE
Throws an exception otherwise. |
TypeVariable |
asTypeVariable()
Casts this type to a
ParameterizedType and returns it if the kind is
Type.Kind.TYPE_VARIABLE
Throws an exception otherwise. |
UnresolvedTypeVariable |
asUnresolvedTypeVariable()
Casts this type to an
UnresolvedTypeVariable and returns it if the kind is
Type.Kind.UNRESOLVED_TYPE_VARIABLE
Throws an exception otherwise. |
VoidType |
asVoidType()
Casts this type to a
VoidType and returns it if the kind is
Type.Kind.VOID
Throws an exception otherwise. |
WildcardType |
asWildcardType()
Casts this type to a
WildcardType and returns it if the kind is
Type.Kind.WILDCARD_TYPE
Throws an exception otherwise. |
static Type |
create(DotName name,
Type.Kind kind)
Creates a type instance of the specified kind.
|
boolean |
equals(Object o)
Compares this Type with another type, and returns true if they are equivalent.
|
int |
hashCode()
Computes a hash code representing this type.
|
abstract Type.Kind |
kind()
Returns the kind of Type this is.
|
DotName |
name()
Returns the raw name of this type.
|
String |
toString()
Returns a string representation for this type.
|
public static final Type[] EMPTY_ARRAY
public static Type create(DotName name, Type.Kind kind)
CLASS,
directly use the specified name. Types of kind ARRAY parse the name
in the Java reflection format (Java descriptor format changing / to '.',
e.g. "[[[[Ljava.lang.String;"). Types of kind PRIMITIVE parsed using the
primitive descriptor format (e.g. "I" for int).
Types of kind VOID ignore the specified name, and return a void type. All
other types will throw an exception.name - the name to use or parsekind - the kind of type to createIllegalArgumentException - if the kind is no supportedpublic DotName name()
DotName.
Generic values are returned as the underlying raw value. For example,
a wildcard such as ? extends Number, has a raw type of
Number
public abstract Type.Kind kind()
public ClassType asClassType()
ClassType and returns it if the kind is Type.Kind.CLASS
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a classpublic ParameterizedType asParameterizedType()
ParameterizedType and returns it if the kind is
Type.Kind.PARAMETERIZED_TYPE
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a parameterized typepublic TypeVariable asTypeVariable()
ParameterizedType and returns it if the kind is
Type.Kind.TYPE_VARIABLE
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a type variablepublic ArrayType asArrayType()
ArrayType and returns it if the kind is
Type.Kind.ARRAY
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not an array typepublic WildcardType asWildcardType()
WildcardType and returns it if the kind is
Type.Kind.WILDCARD_TYPE
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a wildcard typepublic UnresolvedTypeVariable asUnresolvedTypeVariable()
UnresolvedTypeVariable and returns it if the kind is
Type.Kind.UNRESOLVED_TYPE_VARIABLE
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not an unresolved typepublic PrimitiveType asPrimitiveType()
PrimitiveType and returns it if the kind is
Type.Kind.PRIMITIVE
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a primitive typepublic VoidType asVoidType()
VoidType and returns it if the kind is
Type.Kind.VOID
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a void typepublic String toString()
public boolean equals(Object o)
equals in class Objecto - the type to compare toObject.equals(Object)public List<AnnotationInstance> annotations()
Copyright © 2022 JBoss by Red Hat. All rights reserved.