Interface Type
public interface Type
Describes a class which is being made, or describes an existing class or primitive type.
-
Method Summary
Modifier and TypeMethodDescriptionaddAnnotation
(Object annotationType, boolean visible) Add an annotation to this type, if it's annotatable.Returns a new type instance which supports annotations.asArray()
Returns this type as an array, or else adds a dimension if this type is already an array.box()
Returns an object type for a primitive type, or else returns this type.Class
<?> Returns the Class corresponding to this type, or else null if this type represents a class which is being made.Returns a descriptor string for this type.int
Returns the dimensions of this array type, or else 0 if this type isn't an array.Returns the element type of this array type, or else null if this type isn't an array.void
freeze()
Prevent adding more annotations to this type.static Type
Return a Type corresponding to the given Class.static Type
Return a Type corresponding to the given object parameter.static Type
from
(Object obj, ClassLoader loader) Return a Type corresponding to the given object parameter, as found by the given ClassLoader.static Type
Return a Type corresponding to the given class name or type descriptor.static Type
from
(String str, ClassLoader loader) Return a Type corresponding to the given class name or type descriptor, as found by the given ClassLoader.boolean
isArray()
Returns true if this type is an array.boolean
Returns true if this type is known to be an interface.boolean
isObject()
Returns true if this type is an array, an interface, or a class.boolean
Returns true if this type is an int, boolean, double, etc.name()
Returns the name of this type in Java syntax.Returns this type without any annotations.unbox()
Returns a primitive type for an object type, or else returns null if not applicable.
-
Method Details
-
from
-
from
-
from
Return a Type corresponding to the given class name or type descriptor, as found by the given ClassLoader.- Parameters:
str
- class name or type descriptorloader
- can be null to use the bootstrap ClassLoader
-
from
-
from
Return a Type corresponding to the given object parameter, as found by the given ClassLoader.- Parameters:
obj
- Class, String, ClassMaker, Variable, Field, FieldMaker, or ClassDescloader
- can be null to use the bootstrap ClassLoader
-
name
String name()Returns the name of this type in Java syntax. -
descriptor
String descriptor()Returns a descriptor string for this type. -
classType
Class<?> classType()Returns the Class corresponding to this type, or else null if this type represents a class which is being made. -
isPrimitive
boolean isPrimitive()Returns true if this type is an int, boolean, double, etc. -
isObject
boolean isObject()Returns true if this type is an array, an interface, or a class. -
isInterface
boolean isInterface()Returns true if this type is known to be an interface. -
isArray
boolean isArray()Returns true if this type is an array. -
elementType
Type elementType()Returns the element type of this array type, or else null if this type isn't an array. -
dimensions
int dimensions()Returns the dimensions of this array type, or else 0 if this type isn't an array. -
asArray
Type asArray()Returns this type as an array, or else adds a dimension if this type is already an array. If this type is annotatable, then the returned instance will also be annotatable, but it won't initially have any annotations. -
box
Type box()Returns an object type for a primitive type, or else returns this type. If this type is annotatable, then the returned instance will also be annotatable, and it will have a copy of all the annotations added so far. -
unbox
Type unbox()Returns a primitive type for an object type, or else returns null if not applicable. If this type is annotatable, then the returned instance will also be annotatable, and it will have a copy of all the annotations added so far. -
annotatable
Type annotatable()Returns a new type instance which supports annotations. If this type is already annotatable, then the new instance will have a copy of all the annotations added so far.Note: The
hashCode
andequals
methods ignore annotations because annotations don't affect linkage rules. -
addAnnotation
Add an annotation to this type, if it's annotatable. Once this type has been used, it becomesfrozen
and no more annotations can be added. Instead, call theannotatable
method to obtain a new instance.- Parameters:
annotationType
- name or class which refers to an annotation interfacevisible
- true if annotation is visible at runtime- Throws:
IllegalStateException
- if this type isn't annotatable or it's frozenIllegalArgumentException
- if the annotation type is unsupported
-
freeze
void freeze()Prevent adding more annotations to this type. -
unannotated
Type unannotated()Returns this type without any annotations.
-