What is the possible benefit (if any) of allowing recursive contructors?
- by Penang
In Java, constructors cannot be recursive. Compile time error: "recursive constructor invocation". Let's assume that we did not have this restriction.
Things to keep in mind:
The return type of a constructor is void. Since it is a void method you can't harness the complete power of recursion.
A constructor can invoke itself (or any other constructor) using this(). But a "call to this must be first statement in constructor"
We could use non local data between consecutive calls to still have some possible gain from recursive constructors.
Would there be any benefit from allowing recursive constructors?