In the Java SE 8 specific JSR 363 implementation Otavio and I tried to use
Optional, but see the comments in
it caused problems with the type-safe Quantity mechanism.
Can't recall the exact details, but there must have been a conflict when
using another generic type like Quantity<Q> or similar as <T> of Optional.
If the <T> of Bean<T> and Optional<T> 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.
So trying to add these methods could be safer based on my experience with
Optional.
Werner
On Wed, Oct 12, 2016 at 10:43 AM, <cdi-dev-request(a)lists.jboss.org> wrote:
Send cdi-dev mailing list submissions to
cdi-dev(a)lists.jboss.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.jboss.org/mailman/listinfo/cdi-dev
or, via email, send a message with subject or body 'help' to
cdi-dev-request(a)lists.jboss.org
You can reach the person managing the list at
cdi-dev-owner(a)lists.jboss.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of cdi-dev digest..."
Today's Topics:
1. [JBoss JIRA] (CDI-45) Optional Injection Points
(John Ament (JIRA))
2. [JBoss JIRA] (CDI-45) Optional Injection Points
(Martin Kouba (JIRA))
3. [JBoss JIRA] (CDI-45) Optional Injection Points
(John Ament (JIRA))
4. [JBoss JIRA] (CDI-45) Optional Injection Points
(Martin Kouba (JIRA))
5. [JBoss JIRA] (CDI-489) NonexistentConversationException
thrown at restore view or not? (Tomas Remes (JIRA))
6. [JBoss JIRA] (CDI-45) Optional Injection Points
(Matej Novotny (JIRA))
7. Moving on SERVLET_SPEC-116 (giving servlet beans to servlet
spec) (Antoine Sabot-Durand)
----------------------------------------------------------------------
Message: 1
Date: Tue, 11 Oct 2016 16:50:00 -0400 (EDT)
From: "John Ament (JIRA)" <issues(a)jboss.org>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
To: cdi-dev(a)lists.jboss.org
Message-ID:
<JIRA.12428685.1295838622000.12490.1476219000927(a)Atlassian.JIRA>
Content-Type: text/plain; charset=UTF-8
[
https://issues.jboss.org/browse/CDI-45?page=com.
atlassian.jira.plugin.system.issuetabpanels:comment-
tabpanel&focusedCommentId=13305781#comment-13305781 ]
John Ament commented on CDI-45:
-------------------------------
I really like the idea of {{@Inject Optional<T>}}. I may try to prototype
a CDI extension that does it.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL:
https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to
be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will
not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
------------------------------
Message: 2
Date: Tue, 11 Oct 2016 17:21:00 -0400 (EDT)
From: "Martin Kouba (JIRA)" <issues(a)jboss.org>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
To: cdi-dev(a)lists.jboss.org
Message-ID:
<JIRA.12428685.1295838622000.12514.1476220860783(a)Atlassian.JIRA>
Content-Type: text/plain; charset=UTF-8
[
https://issues.jboss.org/browse/CDI-45?page=com.
atlassian.jira.plugin.system.issuetabpanels:comment-
tabpanel&focusedCommentId=13305785#comment-13305785 ]
Martin Kouba commented on CDI-45:
---------------------------------
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}}).
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL:
https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to
be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will
not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
------------------------------
Message: 3
Date: Tue, 11 Oct 2016 18:38:00 -0400 (EDT)
From: "John Ament (JIRA)" <issues(a)jboss.org>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
To: cdi-dev(a)lists.jboss.org
Message-ID:
<JIRA.12428685.1295838622000.12589.1476225480575(a)Atlassian.JIRA>
Content-Type: text/plain; charset=UTF-8
[
https://issues.jboss.org/browse/CDI-45?page=com.
atlassian.jira.plugin.system.issuetabpanels:comment-
tabpanel&focusedCommentId=13305798#comment-13305798 ]
John Ament commented on CDI-45:
-------------------------------
Underestood. The way I see it, for each Bean of type {{<T>}} there exists
a Bean of type {{Optional<T>}} that shares the same qualifiers but has
scope dependent. Optional beans can't be looked up programmatically.
Another way to do this is to add all methods from
https://docs.oracle.com/
javase/8/docs/api/java/util/Optional.html to Instance, which would be:
* ifPresent
* isPresent
* orElse
* orElseGet
* orElseThrow
So hm.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL:
https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to
be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will
not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
------------------------------
Message: 4
Date: Wed, 12 Oct 2016 02:11:01 -0400 (EDT)
From: "Martin Kouba (JIRA)" <issues(a)jboss.org>
Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
To: cdi-dev(a)lists.jboss.org
Message-ID:
<JIRA.12428685.1295838622000.12813.1476252661033(a)Atlassian.JIRA>
Content-Type: text/plain; charset=UTF-8
[
https://issues.jboss.org/browse/CDI-45?page=com.
atlassian.jira.plugin.system.issuetabpanels:comment-
tabpanel&focusedCommentId=13305826#comment-13305826 ]
Martin Kouba commented on CDI-45:
---------------------------------
-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().ifPresent(...)}} etc. is imho easier to
understand.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL:
https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to
be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will
not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
_______________________________________________
cdi-dev mailing list
cdi-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/cdi-dev
Note that for all code provided on this list, the provider licenses the
code under the Apache License, Version 2 (
http://www.apache.org/
licenses/LICENSE-2.0.html). For all other ideas provided on this list,
the provider waives all patent and other intellectual property rights
inherent in such information.
End of cdi-dev Digest, Vol 71, Issue 25
***************************************