回答編集履歴
1
追記
test
CHANGED
@@ -69,3 +69,63 @@
|
|
69
69
|
|
70
70
|
|
71
71
|
せめてappendメソッドはstaticにした方が分かり易いと思うんですがね。
|
72
|
+
|
73
|
+
こんなイメージで。
|
74
|
+
|
75
|
+
```Java
|
76
|
+
|
77
|
+
@FunctionalInterface
|
78
|
+
|
79
|
+
interface Drawable {
|
80
|
+
|
81
|
+
void draw(String str);
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
static Drawable concatenate(Drawable... tasks) {
|
86
|
+
|
87
|
+
return (str) -> {
|
88
|
+
|
89
|
+
for(Drawable task: tasks) { task.draw(str); }
|
90
|
+
|
91
|
+
};
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
class Main {
|
100
|
+
|
101
|
+
public static void main(String[] args) {
|
102
|
+
|
103
|
+
Drawable task1 = (str) -> System.out.println("task1: " + str);
|
104
|
+
|
105
|
+
Drawable task2 = (str) -> System.out.println("task2: " + str);
|
106
|
+
|
107
|
+
Drawable task3 = (str) -> System.out.println("task3: " + str);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
Drawable.concatenate(task1, task2, task3).draw("hoge");
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/AMhxzA5kTpzFDstU)
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
task1: hoge
|
126
|
+
|
127
|
+
task2: hoge
|
128
|
+
|
129
|
+
task3: hoge
|
130
|
+
|
131
|
+
```
|