ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Validating Objects Through Metadata
Subject:   Multiple occurance of Annotation..
Date:   2005-02-15 04:19:08
From:   vinAnnotation
I would like to know whether its possible to declare multiple times a same annotation:
for e.g.
If I have a annotation say:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MyAnnotation
{
String Name();
}


and use this annotation as following:

@MyAnnotation(Name = "First")
@MyAnnotation(Name = "Second")

public class TestAnnotation
{
}


Is the above usage possible? How?


In C#.NET the above can be done as follows:

[AttributeUsage(AttributeTargets.Class,AllowMultiple=true)]
public class MyAnnotation: Attribute
{
}


and used as:

@MyAnnotation(Name = "First")
@MyAnnotation(Name = "Second")

public class TestAnnotation
{
public TestAnnotation(string name)
{
}
}


Anyone knowing how to achieve the above...
Thanks in advance...


vinAnnotation