mercredi 18 février 2015

Accessing Annotation's Parameter it Construction for Modification

I'm a little confused about exactly how annotations work so I could not locate the answer to this easily, even if it was right in front of my eyes without an explanation.


Lets say for example we have this class



//this happens to be a Spring annotation in this case
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = " not found")
class NotFoundException extends RuntimeException {

public NotFoundException(String resourceName) {
//get access to reason from class's annotation
reason = resourceName + reason;
}
}


How do I get access to the annotation's parameter reason at runtime? Is this even possible? If so, I know reflection is involved, but not completely sure the right way to do it.






Aucun commentaire:

Enregistrer un commentaire