In the following example, the parameter names for the constructor of the anonymous inner class in 'B' change depending on whether the sources are compiled separately or together. This occurs despite using -parameters, which should make the parameter names available during separate compilation.
$ cat A.java
class A {
A(int x, int y) {}
}
$ cat B.java
class B {
{
new A(1, 2) {};
}
}
# when both sources are compiled together, the constructor parameters of the anonymous inner class in B are 'x' and 'y'
$ javac -g -parameters A.java B.java
$ javap -v B\$1
...
B$1(B, int, int);
descriptor: (LB;II)V
flags: (0x0000)
Code:
...
LocalVariableTable:
Start Length Slot Name Signature
0 12 0 this LB$1;
0 12 1 this$0 LB;
0 12 2 x I
0 12 3 y I
MethodParameters:
Name Flags
this$0 final mandated
x
y
# when B is compiled with A on the classpath, the constructor parameters of the anonymous inner class in B are 'x0' and 'x1'
$ javac -g -parameters B.java
$ javap -v B\$1
...
B$1(B, int, int);
descriptor: (LB;II)V
flags: (0x0000)
Code:
...
LocalVariableTable:
Start Length Slot Name Signature
0 12 0 this LB$1;
0 12 1 this$0 LB;
0 12 2 x0 I
0 12 3 x1 I
MethodParameters:
Name Flags
this$0 final mandated
x0
x1
$ cat A.java
class A {
A(int x, int y) {}
}
$ cat B.java
class B {
{
new A(1, 2) {};
}
}
# when both sources are compiled together, the constructor parameters of the anonymous inner class in B are 'x' and 'y'
$ javac -g -parameters A.java B.java
$ javap -v B\$1
...
B$1(B, int, int);
descriptor: (LB;II)V
flags: (0x0000)
Code:
...
LocalVariableTable:
Start Length Slot Name Signature
0 12 0 this LB$1;
0 12 1 this$0 LB;
0 12 2 x I
0 12 3 y I
MethodParameters:
Name Flags
this$0 final mandated
x
y
# when B is compiled with A on the classpath, the constructor parameters of the anonymous inner class in B are 'x0' and 'x1'
$ javac -g -parameters B.java
$ javap -v B\$1
...
B$1(B, int, int);
descriptor: (LB;II)V
flags: (0x0000)
Code:
...
LocalVariableTable:
Start Length Slot Name Signature
0 12 0 this LB$1;
0 12 1 this$0 LB;
0 12 2 x0 I
0 12 3 x1 I
MethodParameters:
Name Flags
this$0 final mandated
x0
x1