Java – the order of automatically wrapped @ repeatable annotations

Before that, I used to manually declare the wrapper annotation using an array, and then call it like this:

@Foos({ @Foo(0),@Foo(1),@Foo(2) })
public void bar() {}

Since I created an array using the {...} initializer, it is very clear that when I access this method later through reflection, the order is the same as declared

However, when I use the new @ repeatable annotation in Java 8, do I promise to keep the order?

I announced a set of simple notes:

public @interface Foos {
  Foo[] value();
}

@Repeatable(Foos.class)
public @interface Foo {
 int value();
}

And run some tests for the most diverse scenarios:

@Foo(0) @Foo(1) @Foo(2)
public void bar1() {}

@Foo(2)
@Deprecated @Foo(5)
@Foo(10)
public void bar2() {}

Everything seems perfect (when accessed through reflection), but I don't want to rely on undocumented things I think so, but I can't find it anywhere! Can anyone know something about it?

Solution

This is what the Java language specification says:

(emphasize my)

So, yes, the order of comments in container comments is the same as that of repeatable comments

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>