|
|
|
|
|
by draluy
3116 days ago
|
|
I understand most of your points, but I disagree when it comes to the Optional part of your article. As stated by Brian Goetz
here (https://stackoverflow.com/questions/26327957/should-java-8-g...), the intent was not to use optional all the time as you suggest, going as far as to say "Optional allows you to completely remove NPEs from your program. ". No they do not, an optional can be null anyway. As explained by Mr Goetz, they should only be used when designing an API, to explain to the consumer that a result may not be returned: "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." I think we should keep in mind this is a type added for the JDK code foremost, and use it in similar use cases, and not see it as a general replacement for nullable values. |
|