Hi,
I am trying to learn
Java Annotations.
This is an article from Sun website that explains using Annotations to add Validity Constraints to JavaBeans Properties.
The article explains the existing validation techniques available (viz. XML Schema, Property Descriptor etc.) and lists all their respective merits and demerits, eventually making the case for Annotations.
In short, what I expected Annotations to do in this case is to shorten the code and make it far more readable allowing the developer to focus on "what" rather than how.
That was until I tried the very 1st example that tries to constrain the length of a field to a maximum of 20:
Custom Annotation code (MaxLength):
and the
test class code is :
However, when I run this code, it simply does not work.
Meaning when an argument of "dfsfjvdvjfdvjhbvdjhvbdjvbdvjbdfvhjbcdjkvndvjn" (say,
string of length more than 20) is supplied at run time, the regular output is obtained even after adding the annotation.
Can anyone help me please?