Created
January 19, 2020 06:27
-
-
Save nkalra0123/3b185ed6ceaff4707e59285ac5f93302 to your computer and use it in GitHub Desktop.
Supplier Functional Interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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