<div dir="ltr"><div><div><div>In the Java SE 8 specific JSR 363 implementation Otavio and I tried to use Optional, but see the comments in <a href="https://github.com/unitsofmeasurement/uom-se/blob/master/src/main/java/tec/uom/se/spi/Range.java">https://github.com/unitsofmeasurement/uom-se/blob/master/src/main/java/tec/uom/se/spi/Range.java</a> it caused problems with the type-safe Quantity mechanism.<br><br></div>Can&#39;t recall the exact details, but there must have been a conflict when using another generic type like Quantity&lt;Q&gt; or similar as &lt;T&gt; of Optional. If the &lt;T&gt; of Bean&lt;T&gt; and Optional&lt;T&gt; were exactly the same it might work, but if types with their own generic elements (Collection, Map or a combination of several with different or nested generics) are used, Optional seems to have some problems and limitations. <br><br></div>So trying to add these methods could be safer based on my experience with Optional.<br><br></div>Werner<br><div><div><div><div><div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span lang="EN-GB"><div style="font-family:arial,helvetica,sans-serif"><br></div></span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Wed, Oct 12, 2016 at 10:43 AM,  <span dir="ltr">&lt;<a target="_blank" href="mailto:cdi-dev-request@lists.jboss.org">cdi-dev-request@lists.jboss.org</a>&gt;</span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">Send cdi-dev mailing list submissions to<br>
        <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a target="_blank" rel="noreferrer" href="https://lists.jboss.org/mailman/listinfo/cdi-dev">https://lists.jboss.org/<wbr>mailman/listinfo/cdi-dev</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:cdi-dev-request@lists.jboss.org">cdi-dev-request@lists.jboss.<wbr>org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:cdi-dev-owner@lists.jboss.org">cdi-dev-owner@lists.jboss.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of cdi-dev digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. [JBoss JIRA] (CDI-45) Optional Injection Points<br>
      (John Ament (JIRA))<br>
   2. [JBoss JIRA] (CDI-45) Optional Injection Points<br>
      (Martin Kouba (JIRA))<br>
   3. [JBoss JIRA] (CDI-45) Optional Injection Points<br>
      (John Ament (JIRA))<br>
   4. [JBoss JIRA] (CDI-45) Optional Injection Points<br>
      (Martin Kouba (JIRA))<br>
   5. [JBoss JIRA] (CDI-489) NonexistentConversationExcepti<wbr>on<br>
      thrown at restore view or not? (Tomas Remes (JIRA))<br>
   6. [JBoss JIRA] (CDI-45) Optional Injection Points<br>
      (Matej Novotny (JIRA))<br>
   7. Moving on SERVLET_SPEC-116 (giving servlet beans to       servlet<br>
      spec) (Antoine Sabot-Durand)<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Tue, 11 Oct 2016 16:50:00 -0400 (EDT)<br>
From: &quot;John Ament (JIRA)&quot; &lt;<a href="mailto:issues@jboss.org">issues@jboss.org</a>&gt;<br>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points<br>
To: <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
Message-ID:<br>
        &lt;JIRA.12428685.1295838622000.<wbr>12490.1476219000927@Atlassian.<wbr>JIRA&gt;<br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
<br>
    [ <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=13305781#comment-13305781">https://issues.jboss.org/<wbr>browse/CDI-45?page=com.<wbr>atlassian.jira.plugin.system.<wbr>issuetabpanels:comment-<wbr>tabpanel&amp;focusedCommentId=<wbr>13305781#comment-13305781</a> ]<br>
<br>
John Ament commented on CDI-45:<br>
------------------------------<wbr>-<br>
<br>
I really like the idea of {{@Inject Optional&lt;T&gt;}}.  I may try to prototype a CDI extension that does it.<br>
<br>
&gt; Optional Injection Points<br>
&gt; -------------------------<br>
&gt;<br>
&gt;                 Key: CDI-45<br>
&gt;                 URL: <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45">https://issues.jboss.org/<wbr>browse/CDI-45</a><br>
&gt;             Project: CDI Specification Issues<br>
&gt;          Issue Type: Feature Request<br>
&gt;          Components: Resolution<br>
&gt;    Affects Versions: 1.0<br>
&gt;            Reporter: Stuart Douglas<br>
&gt;            Priority: Optional<br>
&gt;             Fix For: TBD<br>
&gt;<br>
&gt;<br>
&gt; There are occoasions where it may be useful for some injection points to be optional, e.g.<br>
&gt; @Inject<br>
&gt; @Optional<br>
&gt; MyBean bean;<br>
&gt; This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.<br>
<br>
<br>
<br>
--<br>
This message was sent by Atlassian JIRA<br>
(v6.4.11#64026)<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Tue, 11 Oct 2016 17:21:00 -0400 (EDT)<br>
From: &quot;Martin Kouba (JIRA)&quot; &lt;<a href="mailto:issues@jboss.org">issues@jboss.org</a>&gt;<br>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points<br>
To: <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
Message-ID:<br>
        &lt;JIRA.12428685.1295838622000.<wbr>12514.1476220860783@Atlassian.<wbr>JIRA&gt;<br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
<br>
    [ <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=13305785#comment-13305785">https://issues.jboss.org/<wbr>browse/CDI-45?page=com.<wbr>atlassian.jira.plugin.system.<wbr>issuetabpanels:comment-<wbr>tabpanel&amp;focusedCommentId=<wbr>13305785#comment-13305785</a> ]<br>
<br>
Martin Kouba commented on CDI-45:<br>
------------------------------<wbr>---<br>
<br>
Note that {{Optional}} is not {{Serializable}} and is defined final. So there will be problems with injecting into beans with passivating scope (e.g. {{@SessionScoped}}).<br>
<br>
&gt; Optional Injection Points<br>
&gt; -------------------------<br>
&gt;<br>
&gt;                 Key: CDI-45<br>
&gt;                 URL: <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45">https://issues.jboss.org/<wbr>browse/CDI-45</a><br>
&gt;             Project: CDI Specification Issues<br>
&gt;          Issue Type: Feature Request<br>
&gt;          Components: Resolution<br>
&gt;    Affects Versions: 1.0<br>
&gt;            Reporter: Stuart Douglas<br>
&gt;            Priority: Optional<br>
&gt;             Fix For: TBD<br>
&gt;<br>
&gt;<br>
&gt; There are occoasions where it may be useful for some injection points to be optional, e.g.<br>
&gt; @Inject<br>
&gt; @Optional<br>
&gt; MyBean bean;<br>
&gt; This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.<br>
<br>
<br>
<br>
--<br>
This message was sent by Atlassian JIRA<br>
(v6.4.11#64026)<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Tue, 11 Oct 2016 18:38:00 -0400 (EDT)<br>
From: &quot;John Ament (JIRA)&quot; &lt;<a href="mailto:issues@jboss.org">issues@jboss.org</a>&gt;<br>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points<br>
To: <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
Message-ID:<br>
        &lt;JIRA.12428685.1295838622000.<wbr>12589.1476225480575@Atlassian.<wbr>JIRA&gt;<br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
<br>
    [ <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=13305798#comment-13305798">https://issues.jboss.org/<wbr>browse/CDI-45?page=com.<wbr>atlassian.jira.plugin.system.<wbr>issuetabpanels:comment-<wbr>tabpanel&amp;focusedCommentId=<wbr>13305798#comment-13305798</a> ]<br>
<br>
John Ament commented on CDI-45:<br>
------------------------------<wbr>-<br>
<br>
Underestood.  The way I see it, for each Bean of type {{&lt;T&gt;}} there exists a Bean of type {{Optional&lt;T&gt;}} that shares the same qualifiers but has scope dependent.  Optional beans can&#39;t be looked up programmatically.<br>
<br>
Another way to do this is to add all methods from <a target="_blank" rel="noreferrer" href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html">https://docs.oracle.com/<wbr>javase/8/docs/api/java/util/<wbr>Optional.html</a> to Instance, which would be:<br>
<br>
* ifPresent<br>
* isPresent<br>
* orElse<br>
* orElseGet<br>
* orElseThrow<br>
<br>
So hm.<br>
<br>
&gt; Optional Injection Points<br>
&gt; -------------------------<br>
&gt;<br>
&gt;                 Key: CDI-45<br>
&gt;                 URL: <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45">https://issues.jboss.org/<wbr>browse/CDI-45</a><br>
&gt;             Project: CDI Specification Issues<br>
&gt;          Issue Type: Feature Request<br>
&gt;          Components: Resolution<br>
&gt;    Affects Versions: 1.0<br>
&gt;            Reporter: Stuart Douglas<br>
&gt;            Priority: Optional<br>
&gt;             Fix For: TBD<br>
&gt;<br>
&gt;<br>
&gt; There are occoasions where it may be useful for some injection points to be optional, e.g.<br>
&gt; @Inject<br>
&gt; @Optional<br>
&gt; MyBean bean;<br>
&gt; This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.<br>
<br>
<br>
<br>
--<br>
This message was sent by Atlassian JIRA<br>
(v6.4.11#64026)<br>
<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Wed, 12 Oct 2016 02:11:01 -0400 (EDT)<br>
From: &quot;Martin Kouba (JIRA)&quot; &lt;<a href="mailto:issues@jboss.org">issues@jboss.org</a>&gt;<br>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points<br>
To: <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
Message-ID:<br>
        &lt;JIRA.12428685.1295838622000.<wbr>12813.1476252661033@Atlassian.<wbr>JIRA&gt;<br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
<br>
    [ <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=13305826#comment-13305826">https://issues.jboss.org/<wbr>browse/CDI-45?page=com.<wbr>atlassian.jira.plugin.system.<wbr>issuetabpanels:comment-<wbr>tabpanel&amp;focusedCommentId=<wbr>13305826#comment-13305826</a> ]<br>
<br>
Martin Kouba commented on CDI-45:<br>
------------------------------<wbr>---<br>
<br>
-1 for adding those methods on {{Instance}} and -1 for introducing {{Optional}} built-in bean (mainly due to serialization issues and the need for special handling, e.g. disallow programatic lookup). {{Instance.getOptional().<wbr>ifPresent(...)}} etc. is imho easier to understand.<br>
<br>
&gt; Optional Injection Points<br>
&gt; -------------------------<br>
&gt;<br>
&gt;                 Key: CDI-45<br>
&gt;                 URL: <a target="_blank" rel="noreferrer" href="https://issues.jboss.org/browse/CDI-45">https://issues.jboss.org/<wbr>browse/CDI-45</a><br>
&gt;             Project: CDI Specification Issues<br>
&gt;          Issue Type: Feature Request<br>
&gt;          Components: Resolution<br>
&gt;    Affects Versions: 1.0<br>
&gt;            Reporter: Stuart Douglas<br>
&gt;            Priority: Optional<br>
&gt;             Fix For: TBD<br>
&gt;<br>
&gt;<br>
&gt; There are occoasions where it may be useful for some injection points to be optional, e.g.<br>
&gt; @Inject<br>
&gt; @Optional<br>
&gt; MyBean bean;<br>
&gt; This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.<br>
<br>
<br>
<br>
--<br>
This message was sent by Atlassian JIRA<br>
(v6.4.11#64026)<br>
<br>
______________________________<wbr>_________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a target="_blank" rel="noreferrer" href="https://lists.jboss.org/mailman/listinfo/cdi-dev">https://lists.jboss.org/<wbr>mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a target="_blank" rel="noreferrer" href="http://www.apache.org/licenses/LICENSE-2.0.html">http://www.apache.org/<wbr>licenses/LICENSE-2.0.html</a>).  For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
End of cdi-dev Digest, Vol 71, Issue 25<br>
******************************<wbr>*********<br>
</blockquote></div><br></div></div></div></div></div></div></div>