{"id":1676,"date":"2011-03-16T11:08:27","date_gmt":"2011-03-16T05:38:27","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1676"},"modified":"2011-03-16T11:08:27","modified_gmt":"2011-03-16T05:38:27","slug":"meta-annotation-annotate-other-annotation","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/meta-annotation-annotate-other-annotation\/","title":{"rendered":"Meta Annotation &#8211; annotate other annotation"},"content":{"rendered":"<p><a title=\"Introduction to annotation\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/introduction-to-annotation-in-java\/\" target=\"_blank\">In Previous article, we have seen that what are the types of annotation provided by the JAVA.<\/a><\/p>\n<p><strong>What is Meta Annotation ?<\/strong><\/p>\n<p>Fortunately Java allows us to define our own annotation. The annotations which are used to define\u00a0costume\u00a0annotations are known as &#8220;<strong>Meta Annotation<\/strong>&#8220;.<\/p>\n<p>There are four annotation types in the &#8220;<em>java.lang.annotation&#8221;<\/em> package. These so-called meta-annotations are used to annotate other annotation types.<\/p>\n<div class=\"mceTemp mceIEcenter\" style=\"text-align: left;\">\n<dl id=\"attachment_1678\" class=\"wp-caption aligncenter\" style=\"width: 449px;\">\n<dt class=\"wp-caption-dt\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Inbuilt-Annotation-and-Meta-Annotations-in-JAVA.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1678 \" title=\"Inbuilt Annotation and Meta Annotations in JAVA\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Inbuilt-Annotation-and-Meta-Annotations-in-JAVA.jpg?resize=439%2C305&#038;ssl=1\" alt=\"Inbuilt Annotation and Meta Annotations in JAVA\" width=\"439\" height=\"305\" \/><\/a><\/dt>\n<dd class=\"wp-caption-dd\">Inbuilt Annotation and Meta Annotations in JAVA<\/dd>\n<\/dl>\n<\/div>\n<p><!--more--><br \/>\n<strong>1.   @Documented:<\/strong><br \/>\nIf the Annotation itself is annotated by @Documented, then in the java documentation, <strong>annotation will also be shown with the description of class and members.<\/strong><\/p>\n<p>For Example:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage com.G2.Annotations.Meta;\n\nimport java.lang.annotation.Documented;\n\n@Documented\n@interface Nagpur{}\n\n@interface Mumbai{}\n\n@Mumbai\n@Nagpur\npublic class TestDocumented {\n\n}\n\n<\/pre>\n<p>In above code, when the documentation for the class &#8220;TestDocumented&#8221;\u009d is generated, @Nagpur will be shown in the document whereas Mumbai will not.<\/p>\n<p><strong>2.   @ Inherited:<\/strong><br \/>\nIf any Annotation is marked by @Inherited then the<strong> child class inherits that annotation.<\/strong><br \/>\nExample :<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage com.G2.Annotations.Meta;\n\nimport java.lang.annotation.Inherited;\n\n@Inherited\n@interface Maharashtra {\n}\n\n@interface Gujarat {\n}\n\n@Maharashtra\n@Gujarat\nclass Gujrat_Maharashtra {\n\n}\n\nclass Nag extends Gujrat_Maharashtra {\n\tpublic void display() {\n\t\tSystem.out.println(&quot;Nagpur is in Maharashtra&quot;);\n\t}\n}\n\n<\/pre>\n<p>In above example, there are two annotations defined:  &#8220;@Maharashtra&#8221;\u009d and &#8220;@Gujrat&#8221;\u009d.<br \/>\nSubclass &#8220;Nag&#8221;\u009d inherited annotation &#8220;@Maharashtra&#8221;\u009d only from its parent class &#8220;Gujarat_Maharashtra&#8221;\u009d, because it is marked as @Inherited.<\/p>\n<p><strong>3.\t@Retention<\/strong><br \/>\nDifferent annotation types have different purposes. Some are intended for use with the compiler; others are meant to be reflected dynamically at runtime. <strong>There&#8217;s no reason for a compiler annotation to be available at runtime.<\/strong><br \/>\n<em><strong>This Meta annotation \u2013 @Retention is responsible to specify that how long an annotation type should be retained.<\/strong><\/em><\/p>\n<p>The value attribute is one of the &#8220;<em>java.lang.annotation.Retention&#8221;<\/em> Policy enum constants. The possible values, in order from shortest to longest retention, are as follows:<\/p>\n<p><strong>RetentionPolicy.SOURCE<\/strong><br \/>\nThe annotation will not be included in the class file. This is useful for annotations which are intended for the compiler only.<\/p>\n<p><strong>RetentionPolicy.CLASS<\/strong><br \/>\nThe annotation will be included in the class file, but cannot be read reflectively.<\/p>\n<p><strong>RetentionPolicy.RUNTIME<\/strong><br \/>\nThe annotation can be reflected at runtime.<\/p>\n<p><em>If no @Retention policy is specified, it defaults to RetentionPolicy.CLASS.<\/em><\/p>\n<p><strong>4.\t@Target<\/strong><\/p>\n<p><strong><\/strong><strong>@Target annotation decided which type of elements can be marked by the annotation.<\/strong><\/p>\n<p>If the @Target is method and annotation is applied on any other element lets say class, then compiler will generate an error.<\/p>\n<p>The value attribute is one or more of the &#8220;<em>java.lang.annotation.ElementType<\/em>&#8221; enum constants. Those constants are ElementType.ANNOTATION_TYPE, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, and TYPE.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Meta Annotation and its usage in JAVA<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[3],"tags":[36],"class_list":["post-1676","post","type-post","status-publish","format-standard","hentry","category-java","tag-annotation"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1683,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/reading-and-writing-custom-annotation\/","url_meta":{"origin":1676,"position":0},"title":"Reading and Writing Custom Annotation","author":"Jitendra","date":"March 16, 2011","format":false,"excerpt":"Article on Reading and Writing Custom Annotation with example","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1655,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/introduction-to-annotation-in-java\/","url_meta":{"origin":1676,"position":1},"title":"Introduction to Annotation in JAVA","author":"Jitendra","date":"March 14, 2011","format":false,"excerpt":"Introduction to Annotation in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1959,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/create-servlet-using-annotation\/","url_meta":{"origin":1676,"position":2},"title":"Create Servlet using Annotation &#8211; Servlet 3.0","author":"Jitendra","date":"April 13, 2011","format":false,"excerpt":"Create the Servlet without any deployment descriptor. Using Annotations","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6216,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/performing-load-testing-in-salesforce-using-selenium-and-testng\/","url_meta":{"origin":1676,"position":3},"title":"Performing Load Testing in Salesforce using Selenium and TestNG","author":"Jitendra","date":"August 28, 2017","format":false,"excerpt":"Parallel execution of browsers in Selenium with the help of TestNG and determining maximum operating capacity of custom code in Salesforce","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Selenium Salesforce load Testing","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2207,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/creating-business-service-and-service-program-in-ormb-ccb-oracle-utilities\/","url_meta":{"origin":1676,"position":4},"title":"Creating Business Service and Service Program in ORMB \/ CC&#038;B \/ Oracle Utilities","author":"Jitendra","date":"June 15, 2011","format":false,"excerpt":"Creating Business Service and Service Programin ORMB \/ CC&B \/ Oracle Utilities","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Edit Array Eclipse ORMB \/ CC&B \/ Oracle Utilities","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/06\/Edit-Array-Eclipse-ORMB.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5351,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/test-setup-method-in-apex-test-class\/","url_meta":{"origin":1676,"position":5},"title":"Test Setup method in Apex","author":"Jitendra","date":"February 22, 2016","format":false,"excerpt":"How to use setup method in Apex test classes","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1676"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1676\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}