It's not a secret anymore!*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
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: 19649
    
  18

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 - OCEEJBD 6
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: 19649
    
  18

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: 19649
    
  18

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