June 2018
Beginner
722 pages
18h 47m
English
Here is a trick question: guess the input and the output types of the abstract method of the Supplier<T> interface. The answer is: it accepts no parameters and returns the T type. As you understand now, the difference is in the name of the interface itself. It should give you a hint: the consumer just consumes and returns nothing, while the supplier just supplies without any input. The abstract method of the Supplier<T> interface is T get().
Similar to the previous functions, we can write the supplier generating method:
Supplier<Integer> createSuppplier(int num){ Supplier<Integer> func = new Supplier<Integer>() { public Integer get() { return num; } }; return func;}
We can now write a method that accepts only functions:
void ...Read now
Unlock full access