This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Finding annotations from subclass or child class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Finding annotations from subclass or child class" Watch "Finding annotations from subclass or child class" New topic
Author

Finding annotations from subclass or child class

Eric Juneau
Greenhorn

Joined: Jul 13, 2009
Posts: 28
Hi, this question has probably been answered somewhere, but I wasn't able to come up with good search terms for it. Basically, I am trying to get the annotations for fields in a subclass in the parent class. Example:


The problem is that there are no annotations present for the fields in the superclass's validate. I know that child classes won't inherit annotations of the parent class. But shouldn't it work the other way around?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

What's the definition of @MyAnnotation? More specifically, what are its meta annotations (@Documented, @Inherited, @Retention, @Target, etc)?


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Eric Juneau
Greenhorn

Joined: Jul 13, 2009
Posts: 28
MyAnnotation is defined as such:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

Check out the possible values of RetentionPolicy, and figure out which one you need to use with the @Retention meta annotation.
Eric Juneau
Greenhorn

Joined: Jul 13, 2009
Posts: 28
I added

to my annotation and that worked. Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

You're welcome
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Finding annotations from subclass or child class
 
Similar Threads
static Methods @ Interface
ChildClass childClass=new ParentClass()
Polymorphism applies to instance methods not instance variables?
Help reqd in reflection API
Why the interviewer challenged me?