共用方式為


IAnnotatedElement.GetAnnotationsByType(Class) Method

Definition

Returns annotations that are <em>associated</em> with this element.

[Android.Runtime.Register("getAnnotationsByType", "(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;", "GetGetAnnotationsByType_Ljava_lang_Class_Handler:Java.Lang.Reflect.IAnnotatedElement, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=24)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T extends java.lang.annotation.Annotation" })]
public virtual Java.Lang.Object[]? GetAnnotationsByType (Java.Lang.Class annotationClass);
[<Android.Runtime.Register("getAnnotationsByType", "(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;", "GetGetAnnotationsByType_Ljava_lang_Class_Handler:Java.Lang.Reflect.IAnnotatedElement, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=24)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T extends java.lang.annotation.Annotation" })>]
abstract member GetAnnotationsByType : Java.Lang.Class -> Java.Lang.Object[]
override this.GetAnnotationsByType : Java.Lang.Class -> Java.Lang.Object[]

Parameters

annotationClass
Class

the Class object corresponding to the annotation type

Returns

Object[]

all this element's annotations for the specified annotation type if associated with this element, else an array of length zero

Attributes

Remarks

Returns annotations that are <em>associated</em> with this element.

If there are no annotations <em>associated</em> with this element, the return value is an array of length 0.

The difference between this method and #getAnnotation(Class) is that this method detects if its argument is a <em>repeatable annotation type</em> (JLS 9.6), and if so, attempts to find one or more annotations of that type by "looking through" a container annotation.

The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Added in 1.8.

Java documentation for java.lang.reflect.AnnotatedElement.getAnnotationsByType(java.lang.Class<T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to