Thursday, November 15, 2012



Meta-Annotations are an experiment in annotation inheritance, abstraction and encapsulation with a Java SE mindset
A meta-annotation is any annotation class annotated with @Metatype. The other annotations used on the meta-annotation become part of its definition. If any of those annotations happen to also be meta-annotations, they are unrolled as well and their annotations become part of the definition.


The recursion that is the meta-annotation concept only happens when an annotation is marked as a @javax.annotation.Metatype.
When @Metatype is seen the basic contract is "carry the surrounding annotations forward". When a class, method or other target uses an annotation annotated with @Metatype the annotations on that annotation are "unrolled" or carried forward and effectively placed on that class, method or other target as if they were explicitly declared.
If any of the annotations that are carried forward also are annotated with @Metatype the recursion continues. The result is a simple algorithm or design pattern that provides inheritance or reuse in a way that is not specific to any domain, API, or specification.
APIs and specifications can choose to formally adopt annotation reuse in this fashion, but the core concept and implementations of@Metatype do not need to be expanded to support these APIs or specifications.
The simple elegance of this not being domain specific is that it could be used to combine several annotations from different specifications into one reusable annotation. Say JAX-RS @PathParam("id") with Bean Validation @NotNull to create a new annotation called @ValidId.

Creating Meta-Annotations

If the annotation in question can be applied to ElementType.ANNOTATION_TYPE or ElementType.TYPE, creating a meta-annotation version of it is quite easy.
public @interface ContainerManagedTransactions {
When the annotation in question cannot be applied to ElementType.ANNOTATION_TYPE or ElementType.TYPE, things get interesting. This is where meta-annotations depart from things like @Stereotype. The goal of meta-annotations is to be completely generic and not specific to any one domain or API. A such, you cannot really require all existing APIs change to allow for meta-annotations. The goal is that meta-annotations can be used generically and do not need to be "designed" into an API.
To allow annotations that apply to FIELDMETHODPARAMETERCONSTRUCTORLOCAL_VARIABLE, or PACKAGE, as well as any other location where annotations may be applied in the future a compromise is made.
import javax.ejb.Schedule;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


public @interface Daily {
    public static class $ {

        @Schedule(second = "0", minute = "0", hour = "0", month = "*", dayOfWeek = "*", year = "*")
        public void method() {
An inner class named $. This is enough to bind together the @Daily and @Schedule in the context to which they both apply.
Ugly but effective. Alternate proposals welcome.
The above is considered the public API portion of the meta-annotation concept.
The concept itself is born out of standards based systems like EJB and CDI where annotation processing is invisible to the application itself. In those settings the above is enough and no additional APIs would be needed to support meta-annotations in standard APIs.

Under the covers

The "guts" of this particular implementation is designed to look and feel as much like the reflection API as possible. Obviously, with VM level control, you could do much better. A clean Java SE API might be just what is needed and its very possible that meta-annotations should really be a Java SE concept.
Here's a glimpse as to how things can look under the covers:
final java.lang.reflect.AnnotatedElement annotated = new org.metatype.MetaAnnotatedClass(Triangle.class);

assertTrue(annotated.getAnnotation(Color.class) != null);
assertTrue(!contains(Color.class, annotated.getDeclaredAnnotations()));
assertTrue(contains(Color.class, annotated.getAnnotations()));
assertEquals("red", annotated.getAnnotation(Color.class).value());

assertTrue(annotated.getAnnotation(Red.class) != null);
assertTrue(!contains(Red.class, annotated.getDeclaredAnnotations()));
assertTrue(contains(Red.class, annotated.getAnnotations()));

assertTrue(annotated.getAnnotation(Crimson.class) != null);
assertTrue(contains(Crimson.class, annotated.getDeclaredAnnotations()));
assertTrue(contains(Crimson.class, annotated.getAnnotations()));
The application classes would look like so:
// -> @Red -> @Color
public static class Triangle {


// one level deep
@Target(value = {TYPE})
@Retention(value = RUNTIME)
public static @interface Red {

// two levels deep
@Target(value = {TYPE})
@Retention(value = RUNTIME)
public static @interface Crimson {

Best Practices
It is recommended to have an api package or some other package where "approved' annotations are defined and to prohibit usage of the non-meta versions of those annotations. All the real configuration will then be centralized in the api package and changes to the values of those annotations will be localized to that package and automatically be reflected throughout the application.
An interesting side-effect of this approach is that if the api package where the meta-annotation definitions exist is kept in a separate jar as well, then one can effectively change the configuration of an entire application by simply replacing the api jar.

Future concepts

XML Overriding

The unrolling of meta-annotations happens under the covers. In that same vein, so could the concept of overriding.
The above @Red annotation might theoretically be overridden via xml as follows:

  <org.superbiz.api.Color value="dark red"/>
Or take more complex meta-annotation definition like the following:
package org.superbiz.corn.meta.api;

import javax.ejb.Schedule;
import javax.ejb.Schedules;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


public @interface PlantingTime {
    public static interface $ {

                @Schedule(month = "5", dayOfMonth = "20-Last", minute = "0", hour = "8"),
                @Schedule(month = "6", dayOfMonth = "1-10", minute = "0", hour = "8")
        public void method();
This might theoretically be overridden as:

      <javax.ejb.Schedule month="5" dayOfMonth="15-Last" minute="30" hour="5"/>
      <javax.ejb.Schedule month="6" dayOfMonth="1-15" minute="30" hour="5"/>

Merging or Aggregating definitions
Certain annotations take lists and are designed to be multiples. In the current definition of meta-annotations, the following is illegal.
@RolesAllowed({"Administrator", "SuperUser"})
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Admins {

@RolesAllowed({"Employee", "User"})
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Users {

public static class MyBean {

    public void doSomething() {
        // ...
Here the @Admin and @User annotation each resolve to @RolesAllowed. Since only one @RolesAllowed annotation is allowed on the method per the Java language specification, this results in an error.
The intention is clear however and aggregating metadata together in this way is natural.
A theoretical way to support something like this is with an annotation to describe that this aggregation is intended and desired. Note the addition of the theoretical @Merge annotation.
@RolesAllowed({"Administrator", "SuperUser"})
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Admins {

@RolesAllowed({"Employee", "User"})
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Users {

public static class MyBean {

    public void doSomething() {
        // ...
A new @RolesAllowed annotation would be created containing the list {"Administrator", "SuperUser", "Employee", "User"} and that would represent the final @RolesAllowed usage for the doSomething() method.


Yeroc said...

Like the idea but would it not be better to extend the existing CDI @Stereotype annotation to work like this rather than introducing a new annotation?

Monster said...

Hi. This is quite interesting, but without a license, most devs (including me) would stay away from your code. Could you please add a license in the Github repo?

爸爸 x said...

20170619 junda
oakley sunglasses sale
cheap jerseys wholesale
burberry outlet sale
cheap ray ban sunglasses
adidas uk store
michael kors outlet clearance
cheap nba jerseys
true religion outlet
ray ban sunglasses
nike air max 90

Ajay Raj said...

Great Blog posting...

Rhce Training in Chennai
Red Hat Linux Trainng in Chennai

AYAN SAHA said...

Thanks for sharing This wonderful information, looking to read some more.
Ecare Technologies

DevOps Training Institutes in Bangalore

Cloud Computing Training Institutes in Bangalore

Big Data Training Institutes in Bangalore

kanaga seo said...

Thanks for sharing in this blog...

PLC training in Cochin, Kerala
Automation training in Cochin, Kerala
Embedded System training in Cochin, Kerala
VLSI training in Cochin, Kerala
PLC training institute in Cochin, Kerala
Embedded training in Cochin, Kerala
Best plc training in Cochin, Kerala

Krishna Veni said...

Good and nice blog post, thanks for sharing your information.. it is very useful to me.. keep rocks and updating..

Android Training in chennai | Android course in chennai

Charles V. Mounts said...

Here is how you can download iOS 11 beta 4 for your iPhone or iPad devices. We compiled a detailed guide on how to install iOS 11 beta 4.

luu quoc trung said...

Thank you both for sharing Holy Mass with us each day FNAF Sister Location Juegos Friv Friv 2018 to make yourselves available Friv Twizl Jeux De Twizl Juegos De FNAF Sister Location when we were called out late at night and any other time and for your support and encouragement in every respect. Juegos Friv 2021 Juegos Twizl Juegos Yepi 2017 Juegos De Twizl

ngoem199 said...

Danke, dafur dass Ihr jeden Tag mit uns die Hl. Messe gefeiert habt, fur all die Reparaturen im ganzen Haus Jeux De Friv Jogos Friv Jogos Friv fur Euere Bereitschaft Juegos Friv Juegos Friv Juegos De Friv immer zur Verfugung zu stehen Juegos Geometry Dash Juegos Twizl Twizy Twizl Danke, dass Sie Ihr Muhen um den Aufbau des Leibes Christi mit uns teilten.

ngoem199 said...

A todos que partilham e trabalham sob estas mesmas convicções e princípios Friv Friv 360 Friv4school 2020 Senhor Deputado Cashman, agradeço-lhe a informação. Jeux De Friv 2018 Juegos De Roblox Juegos De Zoxy Mais uma vez, obrigada ao Parlamento por comungar da visão que informa a nova política dos consumidores Juegos Kizi 2017 Juegos Yepi 2017 Twizl 3 Zoxy 2 assente no mercado - a visão de um mercado de consumidores informados e capacitados que procuram e usufruem, com confiança,

Danish Ahmed said...

Thanks for sharing this article, now you can also check your Recuritment & Notification 2017-2018 by following below given links...

fci andhra pradesh watchman recuritment 2017

fci tamilnadu watchman recuritment 2017

xat notification 2018

jkbote polytechnic result 2017

ngoem199 said...

Wir danken Ihnen Friv4school 2018 Gry Friv 2 Gry Friv 5 dass Sie diese Hoffnung mit uns teilen und diesen Schritt auf dem Pilgerweg des Vertrauens Gry Friv Juegos Friv 100 Juegos Friv 1000 mit uns gegangen sind. Juegos Friv 5 Juegos De Friv 2 Juegos Friv 250 Juegos Yepi wir danken Ihnen für das Interesse an unseren Produkten und hoffe

friv 10 said...

gracias por la detallada información. Friv 2019 Gry Friv 2018 Juegos Friv 3 Gracias por compartir sus ideas con nosotros. Gry Friv 3 Jeux De Friv Gracias por vuestras reacciones a las transmisiones que os han hecho. Friv 2019 Juegos Friv 2019 Acogemos con agrado los comentarios de los lectores

pankaj Karnwal said...

Nice article thanks for sharing with us.
bank jobs
sabse hatke
rrb result 2017

mishti said...

Your Meta annotation concept is energetic. From this post, everybody can realize the uniqueness of your level. I suppose, you are very brilliant in different programming languages.
Web application projects

adidas nmd said...

nhl jerseys
cheap ray bans
oakley sunglasses wholesale
ralph lauren polo
fitflops sale clearance
nike blazer pas cher
christian louboutin shoes
cheap ray ban sunglasses
oakley sunglasses
nike outlet

Swetha U said...

Great Blog posting...

PHP Training Institute in Chennai

kanza bengal said...

a pride for me to be able to discuss on a quality website because I just learned to make an article on
cara menggugurkan kandungan

Shawn Williams said...

Mobdro app is an excellent online video streaming software available for all other devices like Android, Windows PC, iPhone and iPads. You may even download it on Amazon fire tv.
Check the process here:
troypoint mobdro

redhattrainingcenter said...

great participation i am passionate on writing java programming always willing to learn object oriented programming updates. especially Code re usability inheritance above you have explain meta annotation concepts i am sure implement this concepts in my Java Training Center no doubt that it will improves my coding skills

Jogos Friv said...

I’m very happy to read this. This is the kind of manual that needs to be given and not the accidental misinformation that is at the other blogs. Appreciate your sharing this greatest doc!
Friv Jogos online

sehatwanita said...

This information is very useful. thank you for sharing. and I will also share information about health through the website

Cara Mengobati radang Usus
Cara Mengatasi sakit pundak dan Leher kaku
Cara Menghilangkan Benjolan di Bibir
Obat Nyeri haid
Tips Menghilangkan Wajah kusam
Cara Mengobati Bisul
solusi masalah kewanitaan

redhattrainingcenter said...
This comment has been removed by the author.
redhattrainingcenter said...

Thanks for sharing informative post. Your Meta annotation concept is unique. It's a great ideal for learn new technology
Networking Training Courses

mety susilawati said...


mety susilawati said...



verizon customer service
verizon prepaid customer service
verizon prepaid customer service
verizon contact number
verizon fios customer service number

mety susilawati said...

Like the idea but would it not be better to extend the existing CDI @Stereotype annotation to work like this rather than introducing a new annotation?

sorry izin share

hana alifian said...

mety susilawati said...

It’s really a cool and helpful piece of info. I am happy that you simply shared this helpful
info with us. Please stay us up to date like this.
Thanks for sharing. | |

hana alifian said...

Very interesting and useful information

mety susilawati said...

It’s really a cool and helpful piece of info. I am happy that you simply shared this helpful
info with us. Please stay us up to date like this.
Thanks for sharing.

Revathy A said...

Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
angularjs Training in marathahalli

angularjs interview questions and answers

angularjs Training in bangalore

angularjs Training in bangalore

angularjs Training in chennai

automation anywhere online Training

simbu said...

Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.

Java training in Bangalore | Java training in Btm layout

Java training in Bangalore | Java training in Marathahalli

Java training in Bangalore | Java training in Btm layout

Java training in Bangalore |Java training in Rajaji nagar

thulasi ragini said...

Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.
python training in rajajinagar
Python training in bangalore
Python training in usa

kevin antony said...

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.

rpa training in chennai
rpa training in bangalore
rpa course in bangalore
best rpa training in bangalore
rpa online training

shalinipriya said...

I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
Data Science training in kalyan nagar
Data Science training in OMR | Data science training in chennai
Data Science training in chennai | Best Data science Training in Chennai
Data science training in velachery | Data Science Training in Chennai
Data science training in tambaram | Data Science training in Chennai
Data science training in jaya nagar | Data science Training in Bangalore

johnsy sai said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
Best Devops Training in pune
excel advanced excel training in bangalore
Devops Training in Chennai

vijay antony said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
selenium training in chennai | selenium course in chennai
selenium training in bangalore | selenium course in bangalore
selenium training in Pune | selenium course in pune | selenium class in pune
selenium training in Pune | selenium course in pune | selenium class in pune
selenium online training | selenium training online | online training on selenium

sandy star said...

Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
Best AWS Training in Chennai | Amazon Web Services Training in Chennai
AWS Training in Bangalore | Amazon Web Services Training in Bangalore
Amazon Web Services Training in Pune | Best AWS Training in Pune

mety susilawati said...

I like that and thanks you for information
izin share guys :)

Dharani M said...

good information
java training in Marathahalli

spring training in Marathahalli

java training institute in Marathahalli

spring and hibernate training in Marathahalli

mounika said...

Nice post..

DOT NET training in btm

dot net training institute in btm

dot net course in btm

best dot net training institute in btm DOT NET training in btm

dot net training institute in btm

dot net course in btm

best dot net training institute in btm

cynthia williams said...

Thanks for sharing this pretty post, it was good and helpful. Share more like this.
ReactJS Training in Chennai
AngularJS Training in Chennai
AngularJS course in Chennai
AWS Training in Chennai
DevOps Training in Chennai
RPA Training in Chennai
R Programming Training in Chennai

alex said...

Come in and win right now. best slot machines Do not lose your luck.

Sumaya Manzoor said...

Excellent blog. Looking for software courses?

Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
German Classes in chennai
PHP Training in Chennai
PHP Training in T Nagar

jefrin adams said...

Good to read thanks for sharing

R programming training institute chennai

mety susilawati said...

Belago said...

На любой вкус светодиодные ленты можно найти в Ekodio, бюджетные и премиум, всех цветов и характеристик

Anbarasan14 said...

This post has really given a great idea on the concept. Thanks to the author of this blog for sharing.

Spoken English Class in Thiruvanmiyur
Spoken English Classes in Adyar
Spoken English Classes in T-Nagar
Spoken English Classes in Vadapalani
Spoken English Classes in Porur
Spoken English Classes in Anna Nagar
Spoken English Classes in Chennai Anna Nagar
Spoken English Classes in Perambur
Spoken English Classes in Anna Nagar West

cynthia williams said...

Hearty thanks to you admin, your blog is awesome and helpful. Keep your blog with latest information.
Robotics Process Automation Training in Chennai
Blue Prism Training in Chennai
UiPath Training in Chennai
Data Science Course in Chennai
RPA Training in Anna Nagar
RPA Training in Chennai
RPA course in Chennai

Sivanandhana Girish said...

This is a very helpful blog for one who needs to learn in a short span of time.

Spoken English Classes in Velachery
Spoken English in Velachery
Spoken English Classes in Tambaram
Spoken English Class in Chrompet
Spoken English Classes in OMR Chennai
Spoken English Classes in Navalur
Spoken English Class in Ambattur
Spoken English Class in Avadi

jenifer irene said...

Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information
Aviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai

kaushik said...

I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
Salesforce Training in Chennai
salesforce training institute in chennai
Web Designing Course in Chennai
Tally Course in Chennai
ReactJS Training in Chennai
microsoft dynamics crm training in chennai
Salesforce Training in Chennai
Salesforce Training in Chennai

sandeep saxena said...

Thanks a lot for your help on this. I look forward to reading more articles from you!
core java training in chennai
core java Training in Velachery
c++ courses in chennai
c c++ courses in chennai
javascript training in chennai
javascript course in chennai
core java Training in OMR
clinical sas training in chennai

service care said...

I enjoy what you guys are usually up too. This sort of clever work and coverage! Keep up the wonderful works guysl.Good going.
lg mobile service center in chennai
lg mobile service center

nikitha josh said...

I read the post and I have really enjoyed your blogs posts. Looking for the next post.
aviation institute in Chennai
Air Hostess Training Institute in Chennai
Airline Courses in Chennai
airport ground staff training in Chennai
Aviation Academy in Chennai
air hostess training in Chennai
airport management courses in Chennai
ground staff training in Chennai

Sadhana Rathore said...

I really admired your post, such great and useful information that you have mentioned here.
AWS Certification in Chennai
AWS course in Chennai
Cloud Computing Training in Chennai
Cloud Computing courses in Chennai
Azure Training in Chennai
Microsoft Azure Training in Chennai
DevOps Training in Chennai
AWS Training in Chennai
AWS course in Chennai

Eillen Sharma said...

Escort service in Gurgaon
Escort service in Gurgaon

Escort service in Kolkata
Escort service in Bangalore
Escort service in Mumbai

Samuel mark said...

contacting Yahoo through Yahoo Contact phone number.If any of your queries is not being resolved in Yahoo, then you can contact Yahoo anytime here.

Contact Yahoo! Customer Service Number Fix Yahoo! Error with Yahoo! Customer .Yahoo phone number for help with Yahoo Mail absolute support for Yahoo !