[
https://issues.apache.org/jira/browse/SLING-8706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17141917#comment-17141917
]
Jörg Hoh commented on SLING-8706:
---------------------------------
I know quite a lot of SlingModels, where fields are marked optional, but later
in the postConstruct method the values are consumed in a way as they are always
present. Using {{Optional}} we can force the developers to pay attention to
the fact that this field cannot be assumed to be filled/available in all cases
(I cannot enforce that these fields are always checked for Null!) In there are
definitely cases, where {{@Default}} cannot compensate for that.
Also i think that the impact on the memory usage and performance is negligible.
> 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
> Time Spent: 2h 10m
> Remaining Estimate: 0h
>
> 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)