I used to use a wrapper annotation declaration manually, with an array, and then called it like this:
@Foos({ @Foo(0), @Foo(1), @Foo(2) }) public void bar() {}
Since I was creating an array with initializers { ... } , it was more than clear that the order should be the same in the declaration when I accessed this method later through Reflection.
However, when I use the new @Repeatable annotation from Java 8, can I guarantee that the order will be saved?
I declared a simple set of annotations:
public @interface Foos { Foo[] value(); } @Repeatable(Foos.class) public @interface Foo { int value(); }
and do some tests with a wide variety of scenarios:
@Foo(0) @Foo(1) @Foo(2) public void bar1() {} @Foo(2) @Deprecated @Foo(5) @Foo(10) public void bar2() {}
and everything works flawlessly (when accessed via Reflection), but I would not want to rely on undocumented materials. It seems obvious to me that it should be so, but I canβt find it anywhere! Can anyone shed some light on this?
source share