There was a class U1 that was extending class U. Class U was empty...
In the constructor of U1 there was this first line, calling the constructor of the superclass...
public U1(Plate plate, int order)
{
super(plate, order);
...
}
Now I want to delete class U1 and do in class U whatever was done in U1 so far... So, now I will not need to call constructor of the superclass since class U is not gonna have any superclass...
Is this(plate, order)
unnecessary and can I omit it?
This is how my constructor of U is gonna look like:
public U(Plate plate, int order)
{
this(plate, order);
...
}
It is unnecessary and I would expect it results in a stack overflow, because you call the constructor itself from within the constructor.
It will result in a compilation error. The JLS section 8.8.7 says:
"It is a compile-time error for a constructor to directly or indirectly invoke itself through a series of one or more explicit constructor invocations involving
this
."
In this case, the constructor invokes itself directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With