Follow these steps to implement the example:
- Create a class named FactorialCalculator. Specify that it implements the Callable interface parameterized by the Integer type:
public class FactorialCalculator implements Callable<Integer> {
- Declare a private Integer attribute called number to store the number that this task will use for its calculations:
private final Integer number;
- Implement the constructor of the class that initializes the attribute of the class:
public FactorialCalculator(Integer number){ this.number=number; }
- Implement the call() method. This method returns the factorial of the number attribute of FactorialCalculator:
@Override public Integer call() throws Exception {
- First, create and ...