Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are java annotation lists supposed to allow an extra comma after the last entry?

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

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

Notice the extra comma after the second @NamedQuery. It seems to compile fine on my machine, but someone else had problems compiling the code on their machine, so I removed it. But I am now curious as to whether it's supposed to be allowed, and if so, what version of java allows it.

I have not been able to find any reference to this anywhere online.

like image 397
HappyEngineer Avatar asked Jul 13 '09 20:07

HappyEngineer


People also ask

What is trailing comma?

Trailing commas (sometimes called "final commas") can be useful when adding new elements, parameters, or properties to JavaScript code. If you want to add a new property, you can add a new line without modifying the previously last line if that line already uses a trailing comma.

When a source code containing an annotation definition is compiled what is the extension?

class file and a source code file, the annotation file must redundantly specify the annotation's bytecode offset and source code index. This can be done in a single . jaif file or two separate . jaif files.

Does Python allow trailing commas?

Python Language Dictionary The trailing comma Like lists and tuples, you can include a trailing comma in your dictionary. PEP 8 dictates that you should leave a space between the trailing comma and the closing brace.

Does a list need commas in Python?

In Python, lists are ordered collections of items that allow for easy use of a set of data. List values are placed in between square brackets [ ] , separated by commas. It is good practice to put a space between the comma and the next value.


1 Answers

I think in this case you're dealing with Array Initializers that allow the extra comma.

Example:

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

This has been part of the JLS from the beginning.

like image 138
Josef Pfleger Avatar answered Sep 21 '22 14:09

Josef Pfleger