I’ve recently installed bytecode outline Eclipse plugin and discovered that my Test class
public class Test {
}
calls java.lang.Object’s constructor
public class Test {
public <init>()V
L0
LINENUMBER 15 L0
ALOAD 0
INVOKESPECIAL java/lang/Object.<init>()V
RETURN
L1
LOCALVARIABLE this LTest; L0 L1 0
MAXSTACK = 1
MAXLOCALS = 1
}
INVOKESPECIAL java/lang/Object.<init>()V means calling java.lang.Object’s constructor
Does it make any sense? Judging by java.lang.Object bytecode
public <init>()V
L0
LINENUMBER 37 L0
RETURN
MAXSTACK = 0
MAXLOCALS = 1
it’s doing nothing. Just returns.
It has to in order to satisfy section 4.9.2 of the JVM specification on structural constraints:
Now the rule could be relaxed for classes which are direct subclasses of
Object– but I doubt that it would have any benefit, and would be inelegant (IMO). What if theObjectconstructor did perform some initialization in the future? Would you really want a spec which allowed you to bypass it?