Post-Incrementing/decrementing in recursive method calls (Java)

Say you have a recursive method, and you post-increment/decrement a value in the recursive call. Why will this result in a stack overflow exception when a pre-increment/decrement will not?

Ex.

numberCount(currentNumber++); //Stack overflow exception

numberCount(++currentNumber); //No stack overflow exception

Thanks in advance for any clarification.

Answers


The first

numberCount(currentNumber++); //Stack overflow exception

is equivalent to:

numberCount(currentNumber);
currentNumber += 1;

while the the second

numberCount(++currentNumber); //No stack overflow exception

is equivalent to

currentNumber += 1;
numberCount(currentNumber);

Need I explain more?


Need Your Help

Question about EBNF notation and JSON

json parsing grammar bnf ebnf

Recently I've been studying parsers and grammars and how they work. I was reading over the formal grammar for JSON at http://www.ietf.org/rfc/rfc4627.txt, which uses EBNF. I was pretty confident ...

Can Models communicate with each other in MVVM

c# .net wpf xaml mvvm

Can a Model communicate with other Models, for my case, can a Model have a list of an other Model, Example :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.