Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:54:17+00:00 2026-05-14T05:54:17+00:00

In Java, constructors cannot be recursive. Compile time error: recursive constructor invocation. Let’s assume

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:54:17+00:00Added an answer on May 14, 2026 at 5:54 am

    Constructors (when they are calling each other) are like methods that return void. Consequently the only way they can produce results is by side-effects. This is then limited to mutating the object they are constructing or by mutating the values passed in as parameters. The latter is a pretty nasty idea in a constructor; a constructor usually takes information from its parameters without mutating them.

    So mutating the object being constructed is the only option in order to have any way to track the progress of the recursion, in order for it to terminate eventually. And it’s very hard to see how that would be easier to write, clearer to read, etc. than a simple loop inside an ordinary constructor.

    Calling another constructor (with this) from within a constructor is of course totally different from using a new expression within a constructor:

    class Node
    {
        Node _left, _right;
    
        public Node(Node left, Node right)
        {
            _left = left != null ? new Node(left._left, left._right) : null;
            _right = right != null ? new Node(right._left, right._right) : null;
        }
    }
    

    Here the Node constructor calls itself, but via a new expression. This is the crucial difference. A new expression produces a value, so this is purely “functional”, non-mutating stuff, and provides a convenient way to make a deep copy of the tree of nodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use this transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/*/channel/item/description">… May 16, 2026 at 2:35 pm
  • Editorial Team
    Editorial Team added an answer There is a brute-force method I sometimes use, but you… May 16, 2026 at 2:35 pm
  • Editorial Team
    Editorial Team added an answer It'll work better if you exclude spaces and quotes from… May 16, 2026 at 2:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

is it possible in java that code in constructor is called only once even
I'm having some trouble using multiple constructors in java. what I want to do
Is there a solution to use a final variable in a Java constructor? The
hei. the language is java. i want to extend this class which the constructor
This is probably obvious, so bear with me. YES, I KNOW THAT java.io.File has
What are the use cases of having two constructors with the same signature? Edit:
I'm very new to Java but I've been developing a habit to use final
So I've been brushing up on my Java skills as of late and have
I wanted to ask what is the idea behind the fact that System.String doesn't
The following code gives a compilation error: class parent { parent(int a){} } class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.