import
java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy;
import
java.lang.reflect.Method;
import
java.lang.annotation.Annotation;
@Retention
(RetentionPolicy.RUNTIME)
@interface
customAnnotation {
public
String key();
public
String value();
}
public
class
GFG {
@customAnnotation
(key =
"AvengersLeader"
,
value =
"CaptainAmerica"
)
public
static
void
getCustomAnnotation()
{
try
{
Class c = GFG.
class
;
Method[] methods = c.getMethods();
Method method =
null
;
for
(Method m : methods) {
if
(m.getName().equals(
"getCustomAnnotation"
))
method = m;
}
Annotation[] annotation = method.getDeclaredAnnotations();
for
(Annotation a : annotation) {
customAnnotation self = (customAnnotation)a;
System.out.println(
"Annotation details"
);
System.out.println(
"key: "
+ self.key());
System.out.println(
"value: "
+ self.value());
}
}
catch
(Exception e) {
e.printStackTrace();
}
}
public
static
void
main(String args[])
{
getCustomAnnotation();
}
}