Java - Annotation Member Primitive Type

Introduction

The following code declares an annotation type called MyAnno:

  
@interface MyAnno { 
        byte a(); 
        short b(); 
        int c(); 
        long d(); 
        float e(); 
        double f(); 
        boolean g(); 
        char h(); 
} 
  

You can use an instance of the MyAnno type as

@MyAnno(a=1, b=2, c=3, d=4, e=12.34F, f=1.89, g=true, h='Y') 

You can use a compile-time constant expression to specify the value for an element of an annotation.

  
@Version(major=2+1, minor=(int)13.2) 
@Version(major=3, minor=13)  

Demo

@interface MyAnno { 
        byte a(); 
        short b(); 
        int c(); 
        long d(); 
        float e(); 
        double f(); 
        boolean g(); 
        char h(); 
} 
@interface Version {
  int major();/*from   w w  w . ja v a 2s.c om*/

  int minor();
}
@MyAnno(a=1, b=2, c=3, d=4, e=12.34F, f=1.89, g=true, h='Y') 
class A{
  @Version(major=2+1, minor=(int)13.2)
  int a;
  @Version(major=3, minor=13)
  int b;

}