public class TypeName extends Object
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.lang.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.
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)
.
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
.
Modifier and Type | Field and Description |
---|---|
static TypeName |
BOOLEAN |
static TypeName |
BYTE |
static TypeName |
CHAR |
static TypeName |
DOUBLE |
static TypeName |
FLOAT |
static TypeName |
INT |
static TypeName |
LONG |
static ClassName |
OBJECT |
static TypeName |
SHORT |
static TypeName |
VOID |
Modifier and Type | Method and Description |
---|---|
TypeName |
box()
Returns a boxed type if this is a primitive type (like
Integer for int ) or
void . |
static TypeName |
get(Type type)
Returns a type name equivalent to
type . |
static TypeName |
get(TypeMirror mirror)
Returns a type name equivalent to
mirror . |
boolean |
isPrimitive() |
String |
toString() |
TypeName |
unbox()
Returns an unboxed type if this is a boxed primitive type (like
int for Integer ) or Void . |
public static final TypeName VOID
public static final TypeName BOOLEAN
public static final TypeName BYTE
public static final TypeName SHORT
public static final TypeName INT
public static final TypeName LONG
public static final TypeName CHAR
public static final TypeName FLOAT
public static final TypeName DOUBLE
public static final ClassName OBJECT
public boolean isPrimitive()
public TypeName box()
Integer
for int
) or
void
. Returns this type if boxing doesn't apply.public TypeName unbox()
int
for Integer
) or Void
. Returns this type if it is already unboxed.UnsupportedOperationException
- if this type isn't eligible for unboxing.public static TypeName get(TypeMirror mirror)
mirror
.Copyright © 2015 Square, Inc.. All Rights Reserved.