I am new in Java 8 and are messing around a little bit.
Now I've tried the andThen
method of the functional interface Consumer in Java 8:
public static void main(String[] args) {
List<Integer> ints = new ArrayList<Integer>();
for (int i = 0; i < 5; i++) {
ints.add(i);
}
Consumer<Integer> cons1 = in -> System.out.println("--> " + in);
ints.forEach(cons1.andThen(in -> System.out.println("-+---> " + in)));
}
It works fine! The output is:
--> 0
-+---> 0
--> 1
-+---> 1
--> 2
-+---> 2
--> 3
-+---> 3
--> 4
-+---> 4
Now, I am asking myself if I can concat the both consumers (with the andThen
method) without creating an own object for the first consumer cons1
?