import
java.lang.annotation.Annotation;
import
java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy;
import
java.lang.reflect.Method;
@Retention
(RetentionPolicy.RUNTIME)
@interface
Demo
{
String str();
int
val();
}
public
class
PackageDemo
{
@Demo
(str =
" Gfg Demo Annotation"
, val =
100
)
public
static
void
gfg()
throws
NoSuchMethodException
{
PackageDemo ob =
new
PackageDemo();
Class c = ob.getClass();
Method m = c.getMethod(
"gfg"
);
Demo annotation = m.getAnnotation(Demo.
class
);
System.out.println(annotation.str() +
" "
+ annotation.val());
Annotation[] gfg_ann = m.getDeclaredAnnotations();
for
(
int
i =
0
; i < gfg_ann.length; i++)
{
System.out.println(gfg_ann[i]);
}
}
public
static
void
main(String args[])
throws
Exception
{
gfg();
}
}