Yes, this is possible. You just need to override the method in the super class and add the desired annotation in the subclass.
In answer to your comment
Edit 1:
Yes, I meant overriding the getter. I'd strongly recommend against
defining the same variable in a parent and child class. I'd consider accessing variables defined in a parent class as a violation of encapsulation. Apart from that, you can get into all sorts of troubles as those variables are NOT actually overridden. Consider the following Base class
public class Base {
public int ggg;
public void test() {
System.out.println("Base test was called");
}
}
and the Child class
public class Child extends Base {
public int ggg;
public void test() {
System.out.println("Child test was called");
}
}
Running main() int the following Test class
public class Test {
public static void main(String[] args) {
Base base = new Child();
base.ggg = 5;
System.out.println(base.ggg);
System.out.println(((Child) base).ggg);
base.test();
((Child) base).test();
}
}
you will get the following output
5
0
Child test was called
Child test was called
The variable ggg exists twice, once in the child class and once in the super class. Depending on how you access the object, you access either one of them. This can not happen with a properly overridden method, as shown when calling test().
Besides, AFAIK, validation should work the same if the annotations as defined on the variable or on the getter.
Just as a side note. "overriding" static methods yields the same (mis-)behavior as "overriding" a variable and is therefore also discouraged.