I use the following code (simplified):
in main:
Foe[] foe = Stream.of(foe_2).map(Mapper_1).map(Mapper_2).toArray(Foe::new); in Mapper_1:
{ System.out.println("Mapper_1"); do stuff } in Mapper_2:
{ System.out.println("Mapper_2"); do other stuff } I need Mapper_1 to be finished before Mapper_2 starts.
The functions called by Mapper_1 and Mapper_2 do not call each other!
What I expected:
Mapper_1 maps all elements of the stream that Stream.of(foe_2) returns, then Mapper_2 maps to the output array, resulting in this output:
Mapper_1 ... Mapper_1 Mapper_2 ... Mapper_2 What happens consistently:
Mapper_1 maps the first element of Stream.of(foe_2) and immediately after that, Mapper_2 takes this first result and maps it, ready to be put into the output array, before Mapper_1 maps the second element, resulting in this output:
Mapper_1 Mapper_2 NullpointerExcpetion I get the Exception because Mapper_1 didn't map all elements and the data-structure is messed up.
Is this normal behavior, which would occur counter-intuitive to me, or am I missing something?