The invokespecial
JVM instruction is used for calling initialisation methods (<init>
) when creating new objects. The description of the instruction suggests (but doesn't clarify) that the decision on whether to call the constructor of a superclass or a constructor of the current class depends on the state of the ACC_SUPER
flag set within the class
file.
From the Sun JVM Specification:
Next, the resolved method is selected for invocation unless all of the following conditions are true:
- The ACC_SUPER flag (see Table 4.1, "Class access and property modifiers") is set for the current class.
-- Source (invokespecial
opcode definition)
The setting of the ACC_SUPER flag indicates which of two alternative semantics for its invokespecial instruction the Java virtual machine is to express; the ACC_SUPER flag exists for backward compatibility for code compiled by Sun's older compilers for the Java programming language. All new implementations of the Java virtual machine should implement the semantics for invokespecial documented in this specification. All new compilers to the instruction set of the Java virtual machine should set the ACC_SUPER flag. Sun's older compilers generated ClassFile flags with ACC_SUPER unset. Sun's older Java virtual machine implementations ignore the flag if it is set.
-- Source (ClassFile
format)
The definition states that the flag is for backward compatibility with old compilers. However it goes on to contradict with Sun's older Java virtual machine implementations ignore the flag if it is set.
Is the flag still used with the invokespecial
opcode? From what I can tell, it seems to hold no purpose and I can't find a resource to suggest it ever did.
Thanks.