When I parse the enum using javap, the arguments of the enumerator constructor pointer seem to be missing, and I cannot understand why.
Here's the listing:
enum Foo { X }
I compile and parse this (in Java 8u60) with this command:
javac Foo.java && javap -c -p Foo
And here is the result that I get:
final class Foo extends java.lang.Enum<Foo> { public static final Foo X; private static final Foo[] $VALUES; public static Foo[] values(); Code: 0: getstatic
My confusion is with the private constructor used to instantiate each enum constant. Disassembly shows that it does not accept arguments ( private Foo(); ), but it certainly accepts arguments. For example, you can see load statements reading the passed enum constant name and serial number, as well as the this pointer and passing them to the superclass constructor , which requires them. The code in the static initializer block also shows that it pushes these arguments onto the stack before calling the constructor.
Now I would suggest that this is just an incomprehensible error in javap, but when I compile the exact same enumeration with the Eclipse compiler and parse it with javap, the constructor is exactly the same except for the arguments:
final class Foo extends java.lang.Enum<Foo> { public static final Foo X; private static final Foo[] ENUM$VALUES; static {}; Code: 0: new
My question is: what is physically different between the javac-compiled enum and the Eclipse compiler, which causes javap not to show constructor arguments for the javac-compiled enum? And is there any difference in error (in javap, in javac or Eclipse)?
java enums javap .class-file ecj
Boann
source share