Should java annotation lists allow an extra comma after the last entry?

I accidentally left an extra comma at the end of one of my annotation lists, but compiled it on my machine. For example:

@NamedQueries({ @NamedQuery(name="name1",query="FROM Foo"), @NamedQuery(name="name2",query="FROM Bar"), })

Note the extra comma after the second @NamedQuery. It seems to be compiling on my machine, but someone had problems compiling the code on their machine, so I deleted it. But now I'm curious if he is allowed to admit, and if so, which version of java allows this.

I could not find a link to this anywhere online.

+7
java annotations
source share
2 answers

I think that in this case you are dealing with array initializers that allow an extra comma.

Example:

 int[] foo = new int[] { 1, 2, 3, }; 

This is part of JLS from the start.

+6
source share

Note that this will work in some annotation processing contexts and not in others. If you use the Sun Command Line APT, this will lead to an unpleasant error. (However, it works great in eclipse)

+4
source share

All Articles