ConstructorWithoutNewDRAFT
One can instantiate a class by simply calling the constructor, like Point(1, 2)
. The new
in front is not needed.
One can write the constructor name, without new, to instantiate a class
The constructor name needs to come after the keyword new to instantiate a class
CorrectionHere is what's right.
One cannot call the constructor without using the new
keyword.
The new
in front stands for the object allocation,
the constructor performs the subsequent object initialization.
Those two parts are inseparable,
thus one always has to write new Point(1, 2)
,
and writing just Point(1, 2)
is a mistake.
Implicit Allocation
String
and array literals also represent objects.
They are allocated implicitly,
without specifying a constructor name or the new
keyword.
Similarly, autoboxing can allocate objects implicitly,
and the +
operator with at least one String
argument
will allocate a new String
.