Skip to content

Instantly share code, notes, and snippets.

@peter-lawrey
Created March 14, 2012 08:31
Show Gist options
  • Save peter-lawrey/2035106 to your computer and use it in GitHub Desktop.
Save peter-lawrey/2035106 to your computer and use it in GitHub Desktop.
A way to associate code with an annotation
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Member;
/**
* @author peter.lawrey
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {
public int value() default 0;
enum HandlesAnnotation implements AnnotationHandler<CustomAnnotation> {
INSTANCE;
@Override
public void process(Model model, Member member, CustomAnnotation ca) {
// do something with a model based on the members details and the annotation state.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment