3 ms·
The authors of Optional intended it to only be used as a return type for library functions, to avoid well-known headaches around documenting the nullability of
by tadfisher 2y ago
The authors of Optional intended it to only be used as a return type for library functions, to avoid well-known headaches around documenting the nullability of these functions [1].
To quote:
> For example, you probably should never use it for something that returns an array of results, or a list of results; instead return an empty array or list. You should almost never use it as a field of something or a method parameter.
[1]: https://stackoverflow.com/questions/26327957/should-java-8-getters-return-optional-type/26328555#26328555 https://stackoverflow.com/questions/26327957/should-java-8-g...
- shepherdjerred 2y agoI think we're in agreement. This is exactly how optional should be used.