Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does this qualify as recursion?

Tags:

java

I am aware that a function calling itself is recursive. But, is an object creating objects of it's own type recursive? Additionally, I have no intention of using this code as it will quite obviously cause problems, I'm only interested in whether or not it qualifies as recursion.

class Cell 
{
    Cell()
    {
        Cell c = new Cell();
    }
} 
like image 720
David Wilson Avatar asked Sep 17 '26 13:09

David Wilson


1 Answers

Indeed it does. The Cell constructor will be called by itself, assuming that some calling code sets off the construction of a Cell instance.

Unless you block the recursion somehow (perhaps with a maximum instance limit), your program will eventually crash.

like image 135
Bathsheba Avatar answered Sep 20 '26 02:09

Bathsheba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!