package com.belazy.annotations;
import java.lang.reflect.Method;
public class Test {
public static void main(String[] args) {
Test t = new Test();
t.calcuate();
try {
Method method = new Test().getClass().getMethod("calcuate");
tax annotation = method.getAnnotation(tax.class);
System.out.println(annotation.type());
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@tax(type="vat", value="5",mode ="percentage")
public void calcuate() {
// TODO Auto-generated method stub
System.out.println("calculate");
}
}
package com.belazy.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface tax {
public String type ();
public String value ();
public String mode();
}
://javabelazy.blogspot.in/
No comments:
Post a Comment
Your feedback may help others !!!