O'Reilly logo

Learning Java Functional Programming by Richard M Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recursion implementation techniques

There are a few implementation issues that should be addressed. These include the use of wrapper methods and short-circuiting the base case. These techniques can assist in the use of recursion.

Using a wrapper method

A wrapper method is used to support recursion. This method will not actually perform recursion but will call one that does. The wrapper method may:

  • Validate parameters
  • Perform initialization
  • Handle exceptions as errors are generated

The following is an example of a wrapper method for the arrayTotal method, which is duplicated here for your convenience:

 public int arrayTotal(int numbers[], int index) { if (index == 0) { return numbers[0]; } else { return numbers[index] + arrayTotal(numbers, index - 1); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required