Java annotation execute a method within the annotation declaration(usage for android)-Collection of common programming errors
I’m fairly new to the annotation terms. I have read some sources and came to the conclusion that non answered my question. Perhaps I googled using the wrong search. Perhaps I overlook, or mayhbe im just clueless..
Anyway here is the deal.
I am busy writing an application that requires “role validation”.
To do this I want to use an annotation.
So something along the line of:
@interface Validate (){
}
What I aim to achieve is sometihng along the lines of:
public @interface Validate() {
public Validate() {
//Do validation stuff
return true/false
}
}
So basically I want to define methods within the annotation. I want to be able to call
@Validate
public void methodThatRequiresAdminRole() {
doStuff();
}
Only admins should be able to enter this method. Otherwise an error should be generated.
so if @validate returns true, the method should be executed
Sorry if I am really unclear. I am not quite sure how to properly ask what I want. So I hope the examples tell the stories.
Hope to read tips and perhaps even an answer soon. Thanks.
** EDIT **
I need to stress out the fact that the code must be used on an android application. So I prefer to not use strange frameworks not meant for android. I have no problem adding a custom library that gives the functionality without any kind of application framework.