mercredi 27 mai 2015

How do I access parameters specified in a Java Annotation? [duplicate]

This question already has an answer here:

Let's say I want an annotation called @Day that takes a parameter of a list of days:

@Day(dayNames={"Monday", "Friday"})
public ModelAndView foo(...) {...}

And @Day does something different based on what dayNames are specified. The logic in the annotation would be simple:

if (dayNames[index].equals("Monday")) {
    return new ModelAndView(...);
}

But in the implementation code of my annotation, I can't figure out how to access what dayNames were provided. How do I access the values passed "into" the annotation?

(For example, the @Secured annotation performs an action based on what roles are specified. I want to access the parameters in that way. And yeah, I've looked at the @Secured source code but it's not readily apparently how they're doing it. Not to me anyway.)





Aucun commentaire:

Enregistrer un commentaire