You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Evgeny Tugarev (Jira)" <ji...@apache.org> on 2019/11/11 17:28:00 UTC

[jira] [Commented] (SLING-8706) Injections for java.util.Optional<> should be automatic optional

    [ https://issues.apache.org/jira/browse/SLING-8706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16971748#comment-16971748 ] 

Evgeny Tugarev commented on SLING-8706:
---------------------------------------

I can have a look on implementing this, however I am slightly concerned that _Optional_ class is not serializable. I think this will introduce an artificial limitation and may be problematic in long run. Please correct me if I am wrong.

> 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)