This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android 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: 20041
    
  30

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 - OCEJPAD 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: 20041
    
  30

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: 20041
    
  30

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding annotations from subclass or child class
 
It's not a secret anymore!