import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String value();
String name();
int age();
String[] newNames();
}
import java.lang.annotation.*;
public @interface MyAnnotation1 {
String value();
String name();
int age();
String[] newNames();
}
import java.lang.annotation.Annotation;
public class MyClassAnnotationMain {
public void myMethod() {
System.out.println("My Method Called");
}
public static void main(String[] args) {
Class test = AnnotationFile.class;
Annotation[] annotations = test.getAnnotations();
for (Annotation annotation : annotations) {
if (annotation instanceof MyAnnotation) {
MyAnnotation myAnnotation = (MyAnnotation) annotation;
System.out.println("name: " + myAnnotation.name());
System.out.println("value: " + myAnnotation.value());
}
}
}
}
No comments:
Post a Comment