File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically pass the value to Annotation

 
Talitha Bell
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I want to pass, dynamic value to the annotation........


I am using @XmlElement annotation there are two attribute in this annotation which I required ,type and name

@XmlElement(type=anyClassName.class, name = "anyValue")

Problem is this I don't know the class name because ,It comes at run time ,Is there any way to pass the information to annotation at runtime like this ,If there is any solution It would be very helpful to me.

class TheClass{

@XmlElement(type=anyClassName.class, name = "anyValue")
someMethod(){
......
}
}
[ October 18, 2008: Message edited by: Talitha ]
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annotations can only be set at compile time; that also why their values can only be compile time constants. The only thing you can do with them at runtime is reading them.

In this case I would say that an interface with getter and setter methods for both class and name would be more appropriate.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic