|
The goal of @ValidateReference is to avoid repeating yourself. If for some reason, the valid values change for latitude and longitude in the Range class below, the only place needed to fix annotations is in the Range class.
class Object1 { B b; @ValidateReference(refClass=B.class, method="range") Range getRange() { return b.getRange(); } class Object2 { B b; @ValidateReference(refClass=B.class, method="range") Range getRange() { return b.getRange(); }
class Object3 { B b; @ValidateReference(refClass=B.class, method="range") Range getRange() { return b.getRange(); }
class B { @NotNull @Valid Range getRange()... }
class Range { @Range(min = -90, max = 90) public BigDouble getLatitude() { ... } @Range(min=-180, max=180) public BigDouble getLongitude() { ... }
}
======================================
A hidden value to @ValidateReference is the case when the Annotation Processor checks the class and method of the annotation to verify their existance. This will give developers at compile time knowledge that all the necessary references exist. This is an advantage that Validator.validateProperty(...) and Validator.validateValue(...) do not have. If the classes are missing, it is only at runtime that the ClassNotFoundException will be thrown for those methods.
Please elaborate on your questions if I didn't answer it.
|