Java annotatation reflection is slightly different from. Net attribute reflection.

Source: Internet
Author: User
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 .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.