VoidMethodNotRecursive
DRAFT

Misconception:

A recursive method needs to return something, so a method with void return type cannot possibly be recursive.

Incorrect

A method with void return type can't be recursive

Correct

A method with void return type can be recursive

Correction
Here 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.

Origin
Where 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).

Language

Java

Concepts

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.