Optional.or(Supplier<? extends Optional<T>> supplier)
See original GitHub issueWould be useful for usecases like:
someOptional = firstSuplier().or(secondSupplier).or(thirdSupplier)
Right now it should be written as
if (!someOptional.isPresent()) {
someOptional = secondSupplier();
}
if (!someOptional.isPresent()) {
someOptional = thirdSupplier();
}
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Is there java.util.Optional.or(Supplier ... - Stack Overflow
I wanted to find a short implementation for the behavior: return another java.util.Optional if the current one is empty. JDK 9 has the...
Read more >Optional (Java SE 10 & JDK 10 ) - Oracle Help Center
Returns an Optional describing the given value, if non- null , otherwise returns an empty Optional . Optional<T>, or(Supplier<? extends Optional<? extends T>> ......
Read more >Java Optional - orElse() vs orElseGet() - Baeldung
Clearly, orElse() takes any parameter of a type T, whereas orElseGet() accepts a functional interface of type Supplier that returns an ...
Read more >Optional or() method in Java with examples - GeeksforGeeks
public Optional<T> or(Supplier<T> supplier). Parameters: This method accepts supplier as a parameter of type T to generate an Optional ...
Read more >Optional (Guava: Google Core Libraries for Java 19.0 API)
A non-null Optional<T> reference can be used as a replacement for a nullable T reference. ... @Beta public abstract T or(Supplier<? extends T>...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Added in Java 9. Could still be useful to people on Java 8
Kevin recently said:
I’ll close this and any other
Optional
feature requests I see floating around.