Description:
As per Section 8.4.1 (Formal Parameters) in JLS 3.0, the grammar specified for variable arity parameter is as follows:
LastFormalParameter:
VariableModifiers Type...opt VariableDeclaratorId
FormalParameter
VariableDeclaratorId:
Identifier
VariableDeclaratorId [ ]
The following code which seems to be valid as per the grammar throws Compilation error:
<code>
public class VarArgs
{
void method1 (Integer... var3[] ){
}
}
</code>
Compilation result is :
<output>
VarArgs.java:3: ')' expected
void method1 (Integer... in[]){
^
VarArgs.java:3: illegal start of type
void method1 (Integer... in[]){
^
VarArgs.java:3: <identifier> expected
void method1 (Integer... in[]){
^
VarArgs.java:3: ';' expected
void method1 (Integer... in[]){
^
VarArgs.java:7: class, interface, or enum expected
}
^
5 errors
</output>
There isnt any mention in the JLS that [] should not appear at the end of the declaration for a variable arity parameter.
The following code compiles without error as expected:
public class VarArgs
{
void method1 (Integer []... var3 ) {
}
}
Tried in :
<version>
bash-3.00$ java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b13)
Java HotSpot(TM) Client VM (build 1.7.0-ea-b13, mixed mode)
bash-3.00$ uname -a
SunOS hrajan 5.10 Generic sun4u sparc SUNW,Sun-Blade-100
</version>