This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClassA { | |
private Collaborator collaborator1; | |
private Collaborator collaborator2; | |
public void methodA() { // changed | |
... | |
} | |
public void methodB() { // affected as well | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SendKakaoCommand implements Command { // new | |
... | |
public void execute() { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Handler { | |
... | |
public void handle(Command command) { | |
command.execute(); | |
} | |
} | |
interface Command { | |
public void execute(); | |
} | |
public class SendEmailCommand implements Command { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Handler { | |
... | |
public void handle(Command command) { | |
switch (command.getType()) { | |
case SEND_EMAIL: | |
String subject = command.getSubject(); | |
String body = renderBody(command.getType(), command.getBodyParams()); | |
emailSender.send(new Email(subject, body)); | |
break; | |
case SEND_KAKAO: // new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Handler { | |
... | |
public void handle(Command command) { | |
switch (command.getType()) { | |
case SEND_EMAIL: | |
String subject = command.getSubject(); | |
String body = renderBody(command.getType(), command.getBodyParams()); | |
emailSender.send(new Email(subject, body)); | |
break; | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://download.java.net/java/ga/jdk11/openjdk-11_osx-x64_bin.tar.gz \ | |
| tar -xz \ | |
&& sudo mv jdk-11.jdk /Library/Java/JavaVirtualMachines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use a lambda expression to create the initial listener | |
// which does nothing | |
HyperlinkListener listener = event -> {}; | |
// these decorators first do their own thing and then call the | |
// decorated listener (the one handed over during construction); | |
// in the end, the last added decorator will act first | |
listener = new ExternalApplicationOpeningHyperlinkListenerDecorator(listener); | |
listener = new BrowserOpeningHyperlinkListenerDecorator(listener); | |
listener = new ServiceRequestHandlingHyperlinkListenerDecorator(listener); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompletableFuture<String> completableFuture | |
= CompletableFuture.supplyAsync(() -> "Hello"); | |
CompletableFuture<String> future = completableFuture | |
.thenApplyAsync(s -> s + " World"); | |
assertEquals("Hello World", future.get()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompletableFuture<String> completableFuture = new CompletableFuture<>(); | |
// ... | |
completableFuture.completeExceptionally( | |
new RuntimeException("Calculation failed!")); | |
// ... | |
completableFuture.get(); // ExecutionException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String name = null; | |
// ... | |
CompletableFuture<String> completableFuture | |
= CompletableFuture.supplyAsync(() -> { | |
if (name == null) { | |
throw new RuntimeException("Computation error!"); | |
} | |
return "Hello, " + name; |