Review request: update javac to properly output mandated parameters in MethodParameters attributes

Alex Buckley alex.buckley at oracle.com
Wed Feb 13 18:05:15 PST 2013


On 2/7/2013 2:41 PM, Alex Buckley wrote:
>>>> *) I believe javac's generated enum constructor has an additional
>>>> parameter accepting the ordinal
>>
>> enum Test {
>>      FOO { },
>>      BAR { };
>> }
>>
>> javap -p Test
>>
>> Compiled from "Test.java"
>> class Test extends java.lang.Enum<Test> {
>>    public static final Test FOO;
>>    public static final Test BAR;
>>    public static Test[] values();
>>    public static Test valueOf(java.lang.String);
>>    Test(java.lang.String, *int*, Test$1);
>>    static {};
>> }
>
> Thanks for this. Since the compiler processing the expression "Test.FOO"
> could be different to the compiler which emitted Test.class, there must
> be a standard way for the Test.FOO compiler to indicate which Test
> constant ought to be instantiated. I will consult with Eclipse ASAP. I
> expect both the String and int parameters will end up as implicitly
> declared.

Having now consulted, I realize it is not necessary to specify that any 
formal parameters are implicitly declared in an enum's default ctor. The 
public static fields which _are_ implicitly declared in an enum type 
serve as the "inter-compiler specification" for access to enum 
constants. That is, the compiler of an expression "Test.FOO" simply 
needs to emit code which accesses the FOO field in class Test. How that 
field is initialized to a suitable instance of Test remains a 
compiler-private detail.

So, JLS 8.8.9 will continue to say that the default ctor constructor has 
no formal parameters. Thus, any parameters which are actually emitted 
must be marked ACC_SYNTHETIC in v52.0 class files, since they are 
neither explicitly nor implicitly declared. (javac already hints at this 
by generating an empty Signature attribute for the default ctor, causing 
javap to show zero parameters for it!)

Alex



More information about the compiler-dev mailing list