June 2018
Intermediate to advanced
280 pages
7h 46m
English
The intent is to convert a method into an object to store it and call it later, be able to track its calls, log, and undo. This is the basic usage of the Consumer<T> class.
In the following code, we are going to create a list of commands and execute them one by one:
jshell> List<Consumer<String>> tasks = List.of(System.out::println, x -> System.out.println(LocalDateTime.now().toString() + " " + x))tasks ==> [$Lambda$192/728258269@6107227e, $Lambda$193/1572098393@7c417213]jshell> tasks.forEach(x -> x.accept(text))Text2017-08-10T08:47:31.673812300 Text
Read now
Unlock full access