Skip to content

Instantly share code, notes, and snippets.

@nkalra0123
Created January 19, 2020 06:27
Show Gist options
  • Save nkalra0123/3b185ed6ceaff4707e59285ac5f93302 to your computer and use it in GitHub Desktop.
Save nkalra0123/3b185ed6ceaff4707e59285ac5f93302 to your computer and use it in GitHub Desktop.
Supplier Functional Interfaces
//Supplier
Optional<Integer> value = Stream.of(1,2,3,4).reduce(new BinaryOperator<Integer>() {
@Override
public Integer apply(Integer x, Integer y) {
return x + y;
}
});
value.orElseGet(new Supplier<Integer>() {
@Override
public Integer get() {
return -1;
}
});
Optional<Integer> value2 = Stream.of(1,2,3,4).reduce((x, y) -> x + y);
value2.orElseGet(() -> -1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment