Please be precise as your observation is in direct conflict with accepted answer here. seem not constrainted is not very precise, either it is or it is not.
javax.validation.constraints.@NotNull
is a JSR validation so it should be covered by above answer.If not , probably you might try commenting in that answer.
I would suggest to post your driver program / set up since I doubt that jsr bean validator might not be getting called in your instantiations.
You should understand that this particular behavior listed in above answer is very specific to bean validation annotation processors & has nothing to do with generic annotation inheritance in Java.
Just off topic but trying to include these answers to understand Annotation Inheritance in Java,
Answer -1
Answer -2
Answer -3
Answer -4 Spring MVC Validations
Just to illustrate , no error messages till line - Bar bar = foo.getBar();
but when I put it through validator , I get the message - bar- may not be null
for both parent & child ,
@java.lang.FunctionalInterface
public interface FooChild extends Foo {
}
and driver program ,
import java.util.Set;
import javax.validation.Configuration;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
public class DriverProgram {
public static void main(String[] args) {
Foo foo = () -> {
return null;
};
Bar bar = foo.getBar();
Configuration<?> config = Validation.byDefaultProvider().configure();
ValidatorFactory factory = config.buildValidatorFactory();
Validator validator = factory.getValidator();
factory.close();
Set<ConstraintViolation<Foo>> violations = validator.validate(foo);
violations.forEach(v -> System.out.println(v.getPropertyPath() + "- " + v.getMessage()));
FooChild fooChild = () -> {
return null;
};
bar = fooChild.getBar();
violations = validator.validate(fooChild);
violations.forEach(v -> System.out.println(v.getPropertyPath() + "- " + v.getMessage()));
}
}