Why are recursive methods usually static in Java?

2019-03-17 01:32发布

I'm reviewing recursion these days and found out that a lot of Java recursive method samples are static. Can somebody explain why?

My guess is that they want to save memory, since logically a "parent" recursive method is staying dumb as long as its children recursive method is running and doesn't return anything yet.

Also please check if the following guess is right:

The static recursive method is running on the same thread while a non-static one may run on separate threads, is this correct or doesn't make any sense?

1条回答
We Are One
2楼-- · 2019-03-17 02:13

Because a recursive method/algorithm is generally controlled solely by its parameters and not by instance variables.

Any method that does not rely on instance variables can (and probably should) be made static.

查看更多
登录 后发表回答