[ https://issues.apache.org/jira/browse/SLING-8706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16974278#comment-16974278 ]
Stefan Seifert commented on SLING-8706: --------------------------------------- there is an stackoverflow article about "Why java.util.Optional is not Serializable" with an answer https://stackoverflow.com/a/24564612 "... the primary design goal for Optional is to be used as the return value of functions when a return value might be absent. ... It was never intended for Optional to be used other ways, such as for optional method arguments or to be stored as a field in an object. And by extension, making Optional serializable would enable it to be stored persistently or transmitted across a network, both of which encourage uses far beyond its original design goal." so the pattern above would somewhat contradict this design goal, although i like the approach as well. > Injections for java.util.Optional<> should be automatic optional > ----------------------------------------------------------------- > > Key: SLING-8706 > URL: https://issues.apache.org/jira/browse/SLING-8706 > Project: Sling > Issue Type: Improvement > Components: Sling Models > Reporter: Jörg Hoh > Priority: Major > > The current approach to support optional injections requires to annotate the > field with {{@Optional}} plus proper handling within the javacode (null > checks etc), which can be forgotten. > So instead of > {code} > @Inject @Optional > String fieldname; > {code} > it should also be possible to use this > {code} > @Inject > Optional<String> fieldname; > {code} > with the very same semantic. But the developer is forced to deal with the > case that the value is not present. -- This message was sent by Atlassian Jira (v8.3.4#803005)