import
java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy;
import
java.lang.reflect.Method;
@Retention
(RetentionPolicy.RUNTIME)
@interface
Annotation {
public
String key();
public
String value();
}
public
class
GFG {
@Annotation
(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 anno = method.getAnnotation(Annotation.
class
);
System.out.println("Annotation
for
Method Object"
+ " having name: " + method.getName());
System.out.println("Key Attribute of Annotation: "
+ anno.key());
System.out.println("Value Attribute of Annotation: "
+ anno.value());
}
catch
(Exception e) {
e.printStackTrace();
}
}
public
static
void
main(String args[])
{
getCustomAnnotation();
}
}