docs: improve execute around

This commit is contained in:
Ilkka Seppälä
2024-04-17 21:21:37 +03:00
parent 9615fd9e72
commit 59d3e52434
3 changed files with 57 additions and 32 deletions
@@ -30,7 +30,7 @@ import java.util.Scanner;
import lombok.extern.slf4j.Slf4j;
/**
* The Execute Around idiom specifies executable code before and after a method. Typically
* The Execute Around idiom specifies executable code before and after a method. Typically,
* the idiom is used when the API has methods to be executed in pairs, such as resource
* allocation/deallocation or lock acquisition/release.
*
@@ -47,9 +47,7 @@ public class App {
public static void main(String[] args) throws IOException {
// create the file writer and execute the custom action
FileWriterAction writeHello = writer -> {
writer.write("Gandalf was here");
};
FileWriterAction writeHello = writer -> writer.write("Gandalf was here");
new SimpleFileWriter("testfile.txt", writeHello);
// print the file contents