java.lang.Object
jdk.jfr.AnnotationElement
描述事件元数据,例如标签、描述和单位。
以下示例显示了如何使用 AnnotationElement 来动态定义事件。
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();
- 自从:
- 9
-
构造方法总结
构造方法构造方法描述AnnotationElement(Class<? extends Annotation> annotationType) 创建一个注解元素以用于动态定义的事件。AnnotationElement(Class<? extends Annotation> annotationType, Object value) 创建一个注解元素以用于动态定义的事件。AnnotationElement(Class<? extends Annotation> annotationType, Map<String, Object> values) 创建一个注解元素以用于动态定义的事件。 -
方法总结
修饰符和类型方法描述final <A> AgetAnnotation(Class<? extends Annotation> annotationType) 如果存在具有相同名称的AnnotationElement,则返回指定类型的第一个注释,否则返回null。返回此AnnotationElement的不可变注解元素列表。long返回此AnnotationElement的类型 ID。返回与此AnnotationElement对应的注释类型的完全限定名称(例如,"jdk.jfr.Label")。返回此AnnotationElement的值。返回一个不可变的描述符列表,描述此AnnotationElement的注解值。以与此AnnotationElement的值描述符匹配的顺序返回一个不可变的注解值列表。boolean如果此AnnotationElement中存在具有指定名称的注解值,则返回true。
-
构造方法详细信息
-
AnnotationElement
public AnnotationElement(Class <? extends Annotation > annotationType, Map <String , Object > values) 创建一个注解元素以用于动态定义的事件。支持的值类型是
byte、int、short、long、double、float、boolean、char和String。不支持枚举、数组和类。如果
annotationType有注释(直接存在、间接存在或关联),则这些注释将被递归包含。但是,annotationType和递归找到的任何注释都必须具有MetadataDefinition注释。要静态定义事件,请参阅
Event类。- 参数:
annotationType- 接口扩展java.lang.annotation.Annotation,而不是nullvalues- 一个Map,其键与指定注释接口的方法名称匹配- 抛出:
IllegalArgumentException- 如果值/键是null,则使用了不受支持的值类型,或者使用了与annotationType中的签名不匹配的值/键
-
AnnotationElement
创建一个注解元素以用于动态定义的事件。支持的值类型是
byte、int、short、long、double、float、boolean、char和String。不支持枚举、数组和类。如果
annotationType有注释(直接存在、间接存在或关联),那么这些注释将被递归包含。但是,annotationType和递归找到的任何注释都必须具有MetadataDefinition注释。要静态定义事件,请参阅
Event类。- 参数:
annotationType- 接口扩展java.lang.annotation.Annotation,而不是nullvalue- 匹配指定annotationType的value方法的值- 抛出:
IllegalArgumentException- 如果值/键是null,则使用了不受支持的值类型,或者使用了与annotationType中的签名不匹配的值/键
-
AnnotationElement
创建一个注解元素以用于动态定义的事件。支持的值类型是
byte、short、int、long、double、float、boolean、char和String。不支持枚举、数组和类。如果
annotationType有注释(直接存在、间接存在或关联),那么这些注释将被递归包含。但是,annotationType和递归找到的任何注释都必须具有MetadataDefinition注释。要静态定义事件,请参阅
Event类。- 参数:
annotationType- 扩展 java.lang.annotation.Annotation 的接口,而不是null
-
-
方法详情
-
getValues
以与此AnnotationElement的值描述符匹配的顺序返回一个不可变的注解值列表。- 返回:
-
值列表,而不是
null
-
getValueDescriptors
返回一个不可变的描述符列表,描述此AnnotationElement的注解值。- 返回:
-
这个
Annotation的值描述符列表,而不是null
-
getAnnotationElements
返回此AnnotationElement的不可变注解元素列表。- 返回:
-
元注释列表,而不是
null
-
getTypeName
返回与此AnnotationElement对应的注释类型的完全限定名称(例如,"jdk.jfr.Label")。- 返回:
-
输入名称,而不是
null
-
getValue
返回此AnnotationElement的值。- 参数:
name- 注释接口中方法的名称,而不是null。- 返回:
-
注解值,而不是
null。 - 抛出:
IllegalArgumentException- 如果注释中不存在具有指定名称的方法
-
hasValue
如果此AnnotationElement中存在具有指定名称的注解值,则返回true。- 参数:
name- 要查找的注释接口中的方法名称,而不是null- 返回:
true如果方法存在,false否则
-
getAnnotation
如果存在具有相同名称的AnnotationElement,则返回指定类型的第一个注释,否则返回null。- 类型参数:
A- 要查询并返回的注释类型(如果存在)- 参数:
annotationType- 注释类型对应的Class object,不是null- 返回:
-
此元素对指定注释类型的注解(如果存在),否则为
null
-
getTypeId
public long getTypeId()返回此AnnotationElement的类型 ID。ID 是 Java 虚拟机 (JVM) 中类型的唯一标识符。 JVM 实例之间的 ID 可能不同。
- 返回:
- 类型 ID,不是负数
-