(String[] args)
| 6 | |
| 7 | public class Macro { |
| 8 | public static void main(String[] args) { |
| 9 | List<Runnable> macro = new ArrayList<>( |
| 10 | Arrays.asList( |
| 11 | () -> System.out.print("Hello "), |
| 12 | () -> System.out.println("World! ") |
| 13 | )); |
| 14 | macro.forEach(Runnable::run); |
| 15 | macro.add( |
| 16 | () -> System.out.print("I'm the command pattern!") |
| 17 | ); |
| 18 | macro.forEach(Runnable::run); |
| 19 | } |
| 20 | } |
| 21 | /* Output: |
| 22 | Hello World! |