Depends on what you mean by "persistent". I think you could mean something implied in the question, so here's a little Q & A:
Is the annotation order constant?
Yes, it is written in a .class file in an order that does not change.
Does the order of annotations in the .class file indicate the order of annotations in the source code?
Yes. If you compile your code ...
@Column(length = 256) @NotBlankConstraint(message = "The application title must be set.") @Size(min = 1, max = 256, message = "The application title must be set and not longer than 250 characters.") private String title;
and check the javap -v checkbox:
#67 = Utf8 Ljavax/validation/constraints/Size; ... private java.lang.String title; descriptor: Ljava/lang/String; flags: ACC_PRIVATE RuntimeVisibleAnnotations: 0:
If you change the order of annotations, the order in the byte code will also change. Tested with OpenJDK 1.8.0_121, but I think the case is for earlier JDKs too.
Is the order from the bytecode saved by the getAnnotations() method?
Yes, from what I see, it sequentially returns the same order as in the byte code in the .class file.
Is getAnnotations() guaranteed reflection of the future bytecode annotation order?
Not. As another answer answered, this behavior is not documented, so it cannot be used in a public library.
However, there are subtle signs that order must be maintained in some way.
Now, If this were guaranteed, should this order be used to annotate some previous annotations?
This is a matter of taste, but I would say that most Java programmers will not like it. It would not be too intuitive and readable code. I would suggest grouping annotations like
@ValidationGroup( validators = { @NotNull, @NotEmpty }, message = "User name must be filled." ) public String getUsername();
The problem is that you cannot have an array of “any annotation”, and since there is no inheritance, it cannot be done (Java 1.8). Thus, various frameworks resort to the use of Bean Validation - see the concept of groups.
Finally, I would prefer Eric's comment to check out JSR 303, it's pretty well done and also integrated into many other libraries like RestEasy.