Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Annotations; How can I change value of a field?

807580Jul 29 2010 — edited Jul 29 2010
Hi,

I am relatively new to annotations and wanted to create a sample annotation just to experiment a little with them. At the moment I already managed to create simple annotation and determine on which field this annotation resided. However I would like to know if it is possible to change a field value from annotations and also whether the way I am doing it is correct. For example, imagine the following code;
public class MyClass{
   
   @ChangeTheFollowing
   private MySecondClass secondClass = new MySecondClass();

}
Now at the moment I am creating a third class which loops through all the fields the MyClass instance and then stops at the field where the annotation is found. I was then going to use Reflection to change a value in MySecondClass instance. However I was wondering if there is any other way how to do this from the Annotation class itself (i.e. - from ChangeTheFollowing) rather then having to have a third class to process the annotations.

Regards,
Sim085
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 26 2010
Added on Jul 29 2010
6 comments
736 views