Where is definition of Method java/lang/Object."<init>":()V?
Solution 1:
A look at the source code of java.lang.Object
(e.g. http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/tip/src/share/classes/java/lang/Object.java) shows that there are no explicit constructors in the Object
class. As such, Object
has a default constructor.
As stated in JLS 8.8.9:
If a class contains no constructor declarations, then a default constructor is implicitly declared. The form of the default constructor for a top level class, member class, or local class is as follows:
- ...
- If the class being declared is the primordial class Object, then the default constructor has an empty body.
So, Object.<init>()
is simply a constructor with an empty body.
In more recent versions (e.g. OpenJDK head), there is an explicit constructor, but, again, it has an empty body:
@IntrinsicCandidate
public Object() {}
Solution 2:
That's JVM-ese efor a method reference. <init>
means 'constructor'. ()V
means: A method that takes no arguments and returns void
(as in, nothing).
In other words this tuple of strings:
java/lang/Object
<init>
()V
refers to the no-args constructor of java.lang.Object
itself. Which definitely exists, it's part of all java distributions.
The reason it is called here is basic java reasons:
- ALL classes MUST have a constructor.
-
ALL constructors MUST begin by invoking either another constructor in the same class, or one of the super constructors. (
this();
orsuper();
in java). - If you fail to write a constructor, java assumes you meant to write
public MyClass() {}
. - If you fail to write a
this()
orsuper()
on the first line, java assumes you meant to writesuper();
and will act as if you did.
Thus, your Person
class has a constructor, and it begins by invoking its parent class's no-args constructor.
Which is java/lang/Object
<init>
()V
.
The only class that is supposed to break this rule is java.lang.Object
itself which has no parent class and doesn't do this. With bytecode hackery you can make classes that break these rules, and a JVM will run that just fine if you really want to. But don't - code in the JVM ecosystem expects you to do these things.