A recursive method needs to return something,
so a method with
void return type cannot possibly be recursive.
A method with void return type can't be recursive
A method with void return type can be recursive
CorrectionHere is what's right.
A recursive method does not necessarily need to return a value. For example, a recursive method might print something, but not actually return a value.
OriginWhere could this misconception come from?
This misconception might originate from students
learning pure functional programming before learning an imperative language.
In that case they encountered recursion as the way to repeat computation,
and all of their functions had to always return a value.
Thus, they associated recursion with functions that return values,
because they had never seen the contrasting case of a recursive procedure
(a “function” that does not return a value, e.g., a
void method in Java).