Package io.micronaut.core.annotation
Class AnnotationClassValue<T>
- java.lang.Object
-
- io.micronaut.core.annotation.AnnotationClassValue<T>
-
- Type Parameters:
T
- The generic type of the underlying class
- All Implemented Interfaces:
Named
,java.lang.CharSequence
public final class AnnotationClassValue<T> extends java.lang.Object implements java.lang.CharSequence, Named
An annotation class value is a reference to a class in annotation metadata. The class may or may not be present on the classpath. If it is present then thegetType()
method will return a non-empty optional.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static AnnotationClassValue<?>[]
EMPTY_ARRAY
An empty array of class values.
-
Constructor Summary
Constructors Constructor Description AnnotationClassValue(java.lang.Class<T> theClass)
Constructs a class value for a type that is present.AnnotationClassValue(java.lang.String name)
Constructs a class value for the type that is not present.AnnotationClassValue(java.lang.String name, boolean instantiated)
Constructs a class value for a type that is present.AnnotationClassValue(T instance)
Constructs a class value for a type that is present.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description char
charAt(int index)
boolean
equals(java.lang.Object o)
java.util.Optional<T>
getInstance()
Returns the backing instance if there is one.java.lang.String
getName()
java.util.Optional<java.lang.Class<T>>
getType()
The type if present on the classpath.int
hashCode()
boolean
isInstantiated()
Return whether the class value is instantiated.int
length()
java.lang.CharSequence
subSequence(int start, int end)
java.lang.String
toString()
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final AnnotationClassValue<?>[] EMPTY_ARRAY
An empty array of class values.
-
-
Constructor Detail
-
AnnotationClassValue
@Internal public AnnotationClassValue(java.lang.String name)
Constructs a class value for the type that is not present.- Parameters:
name
- The name of the type.
-
AnnotationClassValue
public AnnotationClassValue(java.lang.Class<T> theClass)
Constructs a class value for a type that is present.- Parameters:
theClass
- The type
-
AnnotationClassValue
@Internal public AnnotationClassValue(@NonNull java.lang.String name, boolean instantiated)
Constructs a class value for a type that is present.- Parameters:
name
- the class nameinstantiated
- Whether at runtime an instance should be instantiated
-
-
Method Detail
-
getInstance
@NonNull public java.util.Optional<T> getInstance()
Returns the backing instance if there is one. Note this method will not attempt to instantiate the class via reflection and is designed for use via byte code generation.- Returns:
- The instance
- Since:
- 1.1
-
isInstantiated
public boolean isInstantiated()
Return whether the class value is instantiated. Normally this is the same as using isPresent ongetInstance()
, except at compilation time where instances are not instantiated.- Returns:
- Whether this class value is instantiated
- Since:
- 1.1
-
getType
public java.util.Optional<java.lang.Class<T>> getType()
The type if present on the classpath.- Returns:
- The type
-
getName
public java.lang.String getName()
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-