I have a class as follow:
public class MyClass {
private String key;
// Getter And Setter
}
I want to limit key
value(for example it can't have space char), for this I have to define as setter as follow:
public void setKey(String key)
{
if(key.indexOf(" ") != -1)
throw new RuntimeException("");
this.key = key;
}
I used this setter in another class too, Is it possible to define an annotation that when setter method callded, it checked this?
If yes, How?