Reconsider the usage of `Optional<T>` in our API
See original GitHub issueThe early API such as Scheme.tryParse() and Server.activePort() returns an Optional while more recent APIs just return null.
Given that Optional tends to make user code verbose and JDK will nor make Optional a value type due to backward compatibility (which is a shame…), I think it’s better just returning a nullable value.
This guarantees breaking changes, but migration should be as simple as wrapping with Optional.ofNullable(), so … 😅
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
12 recipes for using the Optional class as it's meant to be used
Optional is a container that may hold a value, and it is useless to initialize it with null . API note: The empty()...
Read more >Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >Uses for Optional - java - Stack Overflow
The main design goal of Optional is to provide a means for a function returning a value to indicate the absence of a...
Read more >Best practices for API error handling and troubleshooting
This document provides details about error cases to be managed by your application, and the error codes and explanations you shall refer to...
Read more >RESTful web API design - Best Practices - Microsoft Learn
All functionality should be discoverable so that client applications can fully use it. This guidance describes issues that you should consider ...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

Let’s get rid of all of’em!
Hi @alex-lx! Value types are ‘inline classes’:
Optionalis not an inline class and I guess it will never be so due to backward compatibility reasons.A user who prefers method chaining with
Optionalcould wrap the return value withOptional.ofNullable(...), although it’s verbose. I wish Java introduces operators like?,?.?:once Project Valhalla is ready.