Import java. Lang. annotation. retention;
Import java. Lang. annotation. target;
Import java. Lang. annotation. elementtype;
Import java. Lang. annotation. retentionpolicy;
@ Retention (retentionpolicy. runtime)
@ Target (elementtype. type)
@ Interface classinfo {
String created ();
String createdby ();
String lastmodified ();
String lastmodifiedby ();
Int revision () default 0;
}
@ classinfo (
created = "Jan 31 2005",
createdby = "James Gosling",
lastmodified = "Feb 9 2005 ",
lastmodifiedby = "Ken Arnold",
revision = 3
)
class Foo {
}
Public class clientconsole {
Public static void main (string [] ARGs ){
If (FOO. Class. isannotationpresent (classinfo. Class )){
System. Out. println ("annotatted ");
Classinfo info = Foo. Class. getannotation (classinfo. Class );
System. Out. println (info. Created ());
}
Else {
System. Out. println ("not annotatted ");
}
System. Out. println ("finished ...");
}
}
Only marked as runstate reflection can be accessed, which is quite different from attribue.
(Not suitable. It took two hours to locate the problem .)