I want to have a mechanism for method validation. What I am looking for is:
public void someMethod(@valid String emailAddress, @valid Integer ID) {
}
This is a general purpose class not necessarily java bean. The reason why I want this is that I want to decouple the validation logic away from this particular class.
Also I want to use DRY principle that means if various different methods are going to use the similar parameters so I neither want to duplicate the effort nor want to introduce inconsistencies handling the similar types of inputs.
Moreover, I want to make my code more readable as, otherwise, my method body will be sprinkled with if / then / else validation logic which will make it difficult to understand the actual logic and cause unnecessary distraction.
If my code were annotated with some logic, then someone such as spring has to call it - that part I think I understand. So I am not sure how I can implement this. Will aspect-oriented programming work?
Class<? extends Predicate<?>> value()that will point to the validation class for that parameter, which will be instantiated and tested by your proxy.