Java 11 migration: patterns (remaining b-c) (#1081)
* Moves business-delegate pattern to java 11 * Moves bytecode pattern to java 11 * Moves caching pattern to java 11 * Moves callback pattern to java 11 * Moves chain pattern to java 11 * Moves circuit-breaker pattern to java 11 * Moves collection-pipeline pattern to java 11 * Moves command pattern to java 11 * Moves commander pattern to java 11 * Moves composite pattern to java 11 * Corrects test cases
This commit is contained in:
committed by
Ilkka Seppälä
parent
6ef840f3cf
commit
33ea7335b1
@@ -43,8 +43,7 @@ public final class App {
|
||||
* Program entry point.
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
Task task = new SimpleTask();
|
||||
Callback callback = () -> LOGGER.info("I'm done now.");
|
||||
task.executeWith(callback);
|
||||
var task = new SimpleTask();
|
||||
task.executeWith(() -> LOGGER.info("I'm done now."));
|
||||
}
|
||||
}
|
||||
|
@@ -42,8 +42,7 @@ public final class LambdasApp {
|
||||
* Program entry point.
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
Task task = new SimpleTask();
|
||||
Callback c = () -> LOGGER.info("I'm done now.");
|
||||
task.executeWith(c);
|
||||
var task = new SimpleTask();
|
||||
task.executeWith(() -> LOGGER.info("I'm done now."));
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,8 @@
|
||||
|
||||
package com.iluwatar.callback;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Template-method class for callback hook execution.
|
||||
*/
|
||||
@@ -33,9 +35,7 @@ public abstract class Task {
|
||||
*/
|
||||
final void executeWith(final Callback callback) {
|
||||
execute();
|
||||
if (callback != null) {
|
||||
callback.call();
|
||||
}
|
||||
Optional.ofNullable(callback).ifPresent(Callback::call);
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
|
Reference in New Issue
Block a user