Source Code : An annotation type declaration 2.

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

An annotation type declaration 2.

An annotation type declaration 2.
 

/*
Java 2, v5.0 (Tiger) New Features
by Herbert Schildt
ISBN: 0072258543
Publisher: McGraw-Hill/Osborne, 2004
*/
import java.lang.annotation.*; 
import java.lang.reflect.*; 
 
@Retention(RetentionPolicy.RUNTIME)  
@interface MyAnno { 
  String str(); 
  int val(); 
} 
 
public class Meta1 { 
 
  // myMeth now has two arguments. 
  @MyAnno(str = "Two Parameters", val = 19) 
  public static void myMeth(String str, int i)  
  { 
    Meta1 ob = new Meta1(); 
 
    try { 
      Class c = ob.getClass(); 
 
      // Here, the parameter types are specified. 
      Method m = c.getMethod("myMeth", String.class, int.class); 
 
      MyAnno anno = m.getAnnotation(MyAnno.class); 
  
      System.out.println(anno.str() + " " + anno.val()); 
    } catch (NoSuchMethodException exc) { 
       System.out.println("Method Not Found."); 
    } 
  } 
 
  public static void main(String args[]) { 
    myMeth("test", 10); 
  } 
}           
         
  

Thank with us