the expression this.apply(stringValue)
returns true
on a lambda expression j8Test.PerformChange$$Lambda$2/284720968@2f4d3709
Why does it return true and not false. And why doest it return actually anything at all? (I am not talking about all other objects of type PerformChangeImpl)
private final List<PerformChange> performChangeList = Arrays.asList(
new PerformChangeImpl("1"),
new PerformChangeImpl("2"),
new PerformChangeImpl("3")
);
@FunctionalInterface
interface PerformChange extends Function<String, Boolean> {
default PerformChange performChange(PerformChange input) {
System.out.println("1 this: " + this);
System.out.println("2 input: " + input);
return stringValue -> {
System.out.println("\n3 this: " + this);
System.out.println("4 input: " + input);
if (this.apply(stringValue)) {
System.out.println("5 this: " + this);
return input.apply(stringValue);
}
return false;
};
}
}
class PerformChangeImpl implements PerformChange {
private final String value;
public PerformChangeImpl(String value) {
this.value = value;
}
@Override
public Boolean apply(String string) {
System.out.println("\n6: " + this);
System.out.println("7: " + string);
return true;
}
@Override
public String toString() {
return "obj id: " + value;
}
}
and
private void executePerformChanges() {
System.out.println(performChangeList.stream()
.reduce(PerformChange::performChange)
.orElse(new PerformChangeImpl("4"))
.apply("test"));
}
result in
1 this: obj id: 1
2 input: obj id: 2
1 this: j8Test.PerformChange$$Lambda$2/284720968@2f4d3709
2 input: obj id: 3
3 this: j8Test.PerformChange$$Lambda$2/284720968@2f4d3709
4 input: obj id: 3
3 this: obj id: 1
4 input: obj id: 2
6: obj id: 1
7: test
5 this: obj id: 1
6: obj id: 2
7: test
5 this: j8Test.PerformChange$$Lambda$2/284720968@2f4d3709
6: obj id: 3
7: test
true
Process finished with exit code 0