Guaranteed order of annotations?

Gunnar Morling gunnar at hibernate.org
Fri Jan 13 17:14:13 UTC 2017


Hi,

Is there any order guaranteed in which an element's annotations are
returned by AnnotatedElement#getDeclaredAnnotations()? Specifically,
is this the order in which the annotations are given in the source
code?

Section 9.7.5. of the JLS ("Multiple Annotations of the Same Type")
makes a statement of the source order being considered by the array of
the implicit container annotation created for a repeatable annotation
("[...] all the base annotations in the left-to-right order in which
they appeared in the context").

But I couldn't find any authoritative description on the ordering
behaviour of getDeclaredAnnotations(). Should we assume that we cannot
rely on the order in the source?

Thanks for any pointers,

--Gunnar


More information about the core-libs-dev mailing list