Class AnnotationElement
public final class AnnotationElement extends Object
The following example shows how AnnotationElement can be used to dynamically define events.
List<AnnotationElement> typeAnnotations = new ArrayList<>();
typeAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
typeAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
typeAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
List<AnnotationElement> fieldAnnotations = new ArrayList<>();
fieldAnnotations.add(new AnnotationElement(Label.class, "Message"));
List<ValueDescriptor> fields = new ArrayList<>();
fields.add(new ValueDescriptor(String.class, "message", fieldAnnotations));
EventFactory f = EventFactory.create(typeAnnotations, fields);
Event event = f.newEvent();
event.commit();
- Since:
- 9
Constructor Summary
| Constructor | Description |
|---|---|
AnnotationElement |
Creates an annotation element to use for dynamically defined events. |
AnnotationElement |
Creates an annotation element to use for dynamically defined events. |
AnnotationElement |
Creates an annotation element to use for dynamically defined events. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
final <A> A |
getAnnotation |
Returns the first annotation for the specified type if an AnnotationElement with the same name exists, else null. |
List |
getAnnotationElements() |
Returns an immutable list of annotation elements for this AnnotationElement. |
long |
getTypeId() |
Returns the type ID for this AnnotationElement. |
String |
getTypeName() |
Returns the fully qualified name of the annotation type that corresponds to this AnnotationElement (for example, "jdk.jfr.Label"). |
Object |
getValue |
Returns a value for this AnnotationElement. |
List |
getValueDescriptors() |
Returns an immutable list of descriptors that describes the annotation values for this AnnotationElement. |
List |
getValues() |
Returns an immutable list of annotation values in an order that matches the value descriptors for this AnnotationElement. |
boolean |
hasValue |
Returns true if an annotation value with the specified name exists in this AnnotationElement. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
AnnotationElement
public AnnotationElement(Class<? extends Annotation> annotationType, Map<String,Object> values)
Supported value types are byte, int, short, long, double, float, boolean, char, and String. Enums, arrays and classes, are not supported.
If annotationType has annotations (directly present, indirectly present, or associated), then those annotation are recursively included. However, both the annotationType and any annotation found recursively must have the MetadataDefinition annotation.
To statically define events, see Event class.
- Parameters:
-
annotationType- interface extendingjava.lang.annotation.Annotation, notnull -
values- aMapwith keys that match method names of the specified annotation interface - Throws:
-
IllegalArgumentException- if value/key isnull, an unsupported value type is used, or a value/key is used that doesn't match the signatures in theannotationType
AnnotationElement
public AnnotationElement(Class<? extends Annotation> annotationType, Object value)
Supported value types are byte, int, short, long, double, float, boolean, char, and String. Enums, arrays, and classes are not supported.
If annotationType has annotations (directly present, indirectly present, or associated), then those annotations are recursively included. However, both annotationType and any annotation found recursively must have the MetadataDefinition annotation.
To statically define events, see Event class.
- Parameters:
-
annotationType- interface extendingjava.lang.annotation.Annotation,notnull -
value- the value that matches thevaluemethod of the specifiedannotationType - Throws:
-
IllegalArgumentException- if value/key isnull, an unsupported value type is used, or a value/key is used that doesn't match the signatures in theannotationType
AnnotationElement
public AnnotationElement(Class<? extends Annotation> annotationType)
Supported value types are byte, short, int, long, double, float, boolean, char, and String. Enums, arrays, and classes are not supported.
If annotationType has annotations (directly present, indirectly present or associated), then those annotation are recursively included. However, both annotationType and any annotation found recursively must have the MetadataDefinition annotation.
To statically define events, see Event class.
- Parameters:
-
annotationType- interface extending java.lang.annotation.Annotation, notnull
Method Details
getValues
public List<Object> getValues()
AnnotationElement.- Returns:
- list of values, not
null
getValueDescriptors
public List<ValueDescriptor> getValueDescriptors()
AnnotationElement.- Returns:
- the list of value descriptors for this
Annotation, notnull
getAnnotationElements
public List<AnnotationElement> getAnnotationElements()
AnnotationElement.- Returns:
- a list of meta annotation, not
null
getTypeName
public String getTypeName()
AnnotationElement (for example, "jdk.jfr.Label").- Returns:
- type name, not
null
getValue
public Object getValue(String name)
AnnotationElement.- Parameters:
-
name- the name of the method in the annotation interface, notnull. - Returns:
- the annotation value, not
null. - Throws:
-
IllegalArgumentException- if a method with the specified name does not exist in the annotation
hasValue
public boolean hasValue(String name)
true if an annotation value with the specified name exists in this AnnotationElement.- Parameters:
-
name- name of the method in the annotation interface to find, notnull - Returns:
-
trueif method exists,falseotherwise
getAnnotation
public final <A> A getAnnotation(Class<? extends Annotation> annotationType)
AnnotationElement with the same name exists, else null.- Type Parameters:
A- the type of the annotation to query for and return if it exists- Parameters:
-
annotationType- theClass objectcorresponding to the annotation type, notnull - Returns:
- this element's annotation for the specified annotation type if it exists, else
null
getTypeId
public long getTypeId()
AnnotationElement. The ID is a unique identifier for the type in the Java Virtual Machine (JVM). The ID might not be the same between JVM instances.
- Returns:
- the type ID, not negative
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.