This is part of JDK 9 in the form of or
, which takes a Supplier<Optional<T>>
. Your example would then be:
return serviceA(args)
.or(() -> serviceB(args))
.or(() -> serviceC(args));
For details see the Javadoc or this post I wrote.
More Related Contents:
- Chaining Optionals in Java 8
- Stream.peek() method in Java 8 vs Java 9
- What are functional interfaces used for in Java 8?
- Why filter() after flatMap() is “not completely” lazy in Java streams?
- How to force max to return ALL maximum values in a Java Stream?
- What is the equivalent lambda expression for System.out::println
- Copy a stream to avoid “stream has already been operated upon or closed”
- Does a lambda expression create an object on the heap every time it’s executed?
- Java 8 Nested (Multi level) group by
- Difference between `Optional.orElse()` and `Optional.orElseGet()`
- Precise definition of “functional interface” in Java 8
- Java 8: Difference between method reference Bound Receiver and UnBound Receiver
- Lambda expression vs method reference
- Java 8 Lambda Expressions – what about multiple methods in nested class
- Lambda this reference in java
- java.lang.ClassCastException using lambda expressions in spark job on remote server
- Filter Java Stream to 1 and only 1 element
- Why do I need a functional Interface to work with lambdas?
- Find maximum, minimum, sum and average of a list in Java 8
- Java lambda returning a lambda
- Does Java SE 8 have Pairs or Tuples?
- Java 8 Supplier with arguments in the constructor
- Java 8: Mandatory checked exceptions handling in lambda expressions. Why mandatory, not optional?
- Java access bean methods with LambdaMetafactory
- What kind of List does Collectors.toList() return?
- Java 8 Filter Array Using Lambda
- Lambdas in the classical Operation enum example
- In Java 8 how do I transform a Map to another Map using a lambda?
- Purpose of third argument to ‘reduce’ function in Java 8 functional programming
- Are Java 8 lambdas compiled as inner classes, methods or something else? [duplicate]