Prior to Java 8 it was possible to affect this type of operation using a specialized library such as http://www.functionaljava.org/ or by creating a class and interface first. We will demonstrate the latter approach here.
The interface will permit two methods to be combined. To illustrate this approach, we will declare a class called
Compose. Within the class, we will declare a
CompositionFunction interface, containing a single
call method along with a
compose method. The
compose method returns an instance of the
CompositionFunction interface using two
CompositionFunction interface instances passed to it. The
call method does the actual work.
The first part of the
Compose class and the