No, in fact, the constructors compiled into the class file similar methods that have the name <init> and the void type of the return value. You can see these "<init>" calls in stacks. The expression new Type() compiled as a new statement that just creates an instance of Type and an additional invokation ( invokespecial ) method to one of the constructors declared in Type .
The verifier ensures that such a special method is called exactly once on the newly created instance and that it is called before any other use of the object.
Its just a solution for designing a programming language so that designers do not have a return type in terms of the Java language. After all, new Type(…) is an expression that evaluates to the newly created instance of Type , and you cannot get the return value from the constructor using this programming language construct. Also, if you add a return type, Java will unconditionally assume that it is a method, even if it has the same name as the class.
This is just how it was defined : (This simplifies the analysis of the class definition)
SimpleTypeName in ConstructorDeclarator must be the simple name of the class containing the constructor declaration, or a compile-time error occurs.
In all other respects, a constructor declaration looks like a method declaration that has no result (§8.4.5).
source share