Annotations and Inheritance
back to index
Dynject uses the following rules when handling annotations that are applied to the same method along the inheritance/interface chain:
- A method can have only one annotation of a kind.
- The set of validation annotation that a property or method has is the union of all annotations of the method along the inheritance and interface chain.
- Annotations in the class being validated take precedence over any other
- Annotations in ancestors/interfaces closer to the class being validated take precedence over annotations in ancestors further up in the inheritance chain.
- Annotations in classes take precedence over annotations in interfaces
As a practical example, consider the following diagram:

The annotations that Dynject will consider as applicable to the "Property" property in SomeClass are:
- @Length(min = 5, max = 10) - This annotation is present in the class itself, and takes precedence over similar annotations in BaseClass and IBase
- @Required
- @Normalized( UPPERCASE )
- @Require ("__this.x > 3") (Since annotations in classes take precedence over annotations in interfaces)
Exactly the same logic is applied to annotations present in parameters