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

Jörg Hoh commented on SLING-8706:
---------------------------------

I think everyone agrees, that even with the best approaches and design you 
cannot prevent simple errors, if the user/developer is not trained or is in 
such a hurry that even simple rules are ignored.

And yes, you can write failing code with {{Optional}} as well. But my personal 
impression is that it leads often/most times/often enough to rethink the usage 
of a field. More often than you think of "oh, that String can be {{Null}}, 
let's add a Null check".

Having said that, I think that it could be a nice extension. Probably not 
everyone will benefit from it the same way, but some do.

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

Reply via email to