207. Implementing a Consumer that takes five (or any other arbitrary number of) arguments
Before continuing with this problem, I strongly recommend that you read Problem 206.
Writing a custom Consumer
that takes five arguments can be done as follows:
@FunctionalInterface
public interface FiveConsumer <T1, T2, T3, T4, T5> {
void accept (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);
}
This is the five-arity specialization of the Java Consumer,
just as the built-in BiConsumer
is the two-arity specialization of the Java Consumer
.
We can use FiveConsumer
in conjunction with the PL4 formula, as follows (here, we compute y
for x
= 40.3):
FiveConsumer<Double, Double, Double, Double, Double>
pl4c = (a, b, c, d, x) -> Logistics.pl4(a, b, c, d, x);
pl4c.accept(4.19, -1.10, 12.65, 0.03, 40.3);
The Logistics.pl4()
is the method that contains the formula and displays the result:
public static void pl4(Double a, Double b,
...