Class TypeName
- Direct Known Subclasses:
ArrayTypeName,ClassName,ParameterizedTypeName,TypeVariableName,WildcardTypeName
void. This class is an identifier for primitive
types like int and raw reference types like String and List. It also
identifies composite types like char[] and Set<Long>.
Type names are dumb identifiers only and do not model the values they name. For example, the
type name for java.util.List doesn't know about the size() method, the fact that
lists are collections, or even that it accepts a single type parameter.
Instances of this class are immutable value objects that implement equals() and
hashCode() properly.
Referencing existing types
Primitives and void are constants that you can reference directly: see INT, DOUBLE, and VOID.
In an annotation processor you can get a type name instance for a type mirror by calling
get(TypeMirror). In reflection code, you can use get(Type).
Defining new types
Create new reference types like com.example.HelloWorld with ClassName.get(String, String, String...). To build composite types like char[] and
Set<Long>, use the factory methods on ArrayTypeName, ParameterizedTypeName, TypeVariableName, and WildcardTypeName.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfinal TypeNameannotated(AnnotationSpec... annotations) annotated(List<AnnotationSpec> annotations) box()Returns a boxed type if this is a primitive type (likeIntegerforint) orvoid.protected final List<AnnotationSpec>concatAnnotations(List<AnnotationSpec> annotations) final booleanstatic TypeNameReturns a type name equivalent totype.static TypeNameget(TypeMirror mirror) Returns a type name equivalent tomirror.final inthashCode()booleanbooleanReturns true if this is a boxed primitive type likeInteger.booleanReturns true if this is a primitive type likeint.final StringtoString()unbox()Returns an unboxed type if this is a boxed primitive type (likeintforInteger) orVoid.
-
Field Details
-
VOID
-
BOOLEAN
-
BYTE
-
SHORT
-
INT
-
LONG
-
CHAR
-
FLOAT
-
DOUBLE
-
OBJECT
-
annotations
-
-
Method Details
-
annotated
-
annotated
-
withoutAnnotations
-
concatAnnotations
-
isAnnotated
public boolean isAnnotated() -
isPrimitive
public boolean isPrimitive()Returns true if this is a primitive type likeint. Returns false for all other types types including boxed primitives andvoid. -
isBoxedPrimitive
public boolean isBoxedPrimitive()Returns true if this is a boxed primitive type likeInteger. Returns false for all other types types including unboxed primitives andjava.lang.Void. -
box
Returns a boxed type if this is a primitive type (likeIntegerforint) orvoid. Returns this type if boxing doesn't apply. -
unbox
Returns an unboxed type if this is a boxed primitive type (likeintforInteger) orVoid. Returns this type if it is already unboxed.- Throws:
UnsupportedOperationException- if this type isn't eligible for unboxing.
-
equals
-
hashCode
public final int hashCode() -
toString
-
get
Returns a type name equivalent tomirror. -
get
Returns a type name equivalent totype.
-