Class: Annotation[] getAnnotations() : Class « java.lang « Java by API






Class: Annotation[] getAnnotations()

      

import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
  String stringValue();

  int intValue();
}

@Retention(RetentionPolicy.RUNTIME)
@interface What {
  String description();
}

@What(description = "An annotation test class")
@MyAnnotation(stringValue = "for class", intValue = 100)
public class Main {
  @What(description = "An annotation test method")
  @MyAnnotation(stringValue = "Annotation Example", intValue = 100)
  public static void myMethod(String str, int i) {
  }

  public static void main(String[] arg) throws Exception {
    Main ob = new Main();
    Annotation[] annos = ob.getClass().getAnnotations();

    System.out.println("All annotations for Meta2:");
    for (Annotation a : annos)
      System.out.println(a);
  }
}

   
    
    
    
    
    
  








Related examples in the same category

1.Class: forName(String classDec)
2.Class: getCanonicalName()
3.Class: getClasses()
4.Class: getComponentType()
5.Class: getConstructors()
6.Class: getConstructor(Class...)
7.Class: getDeclaringClass()
8.Class: getDeclaredConstructors()
9.Class: getDeclaredFields()
10.Class: getDeclaredMethods()
11.Class: getDeclaredMethod(String name, Class... parameterTypes)
12.Class: getEnumConstants()
13.Class: getFields()
14.Class: getGenericInterfaces()
15.Class: getGenericSuperclass()
16.Class: getInterfaces()
17.Class: Method getMethod(String name, Class... parameterTypes)
18.Class: getMethods()
19.Class: getModifiers()
20.Class: getName()
21.Class: getPackage()
22.Class: getProtectionDomain()
23.Class: getResource(String name) (absolute from the classpath)
24.Class: getResource(String name) (relative to the class location)
25.Class: getResourceAsStream(String name)
26.Class: getSuperclass()
27.Class: getTypeParameters()
28.Class: isArray()
29.Class: isAssignableFrom(Class cls)
30.Class: isEnum()
31.Class: isInstance(Object obj)
32.Class: isInterface()
33.Class: newInstance()