[cdi-dev] [JBoss JIRA] (CDI-583) Observer resolution doesn't support Lambdas

Antoine Sabot-Durand (JIRA) issues at jboss.org
Fri Feb 12 09:02:00 EST 2016

    [ https://issues.jboss.org/browse/CDI-583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13162231#comment-13162231 ] 

Antoine Sabot-Durand commented on CDI-583:

As discussed in WELD-2108, we should consider adding to the event types, the type defined at Event injection point to satisfy this use case.

But this should be done carefully to see if it doesn't add any regression to event behaviour. 

> Observer resolution doesn't support Lambdas
> -------------------------------------------
>                 Key: CDI-583
>                 URL: https://issues.jboss.org/browse/CDI-583
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Events
>    Affects Versions: 1.2.Final, 2.0-EDR1
>            Reporter: Antoine Sabot-Durand
> As stated in various discussion on JDK8, lambda expressions don't allow to retrieve parameter types by reflection.
> See:
> http://jdk8-dev.openjdk.java.narkive.com/bSPiKxap/jdk-8-lambda-reflection-issues
> As section 10.1 of the spec states:
> bq. The event types of the event include all superclasses and interfaces of the runtime class of the event object.
> In case of a lambda payload, observer resolution will fails when respecting the rule above since parameter type won't be retrieve from the lambda.
> For instance the following code
> {code}
>     @Inject
>     Event<Supplier<String>> stringSupplierEvent;
> ...
>     Supplier<String> stringSupplier = () -> "Hello world";
>     stringSupplierEvent.fire(stringSupplier);
> {code}
> will triggers an observer for {{Supplier}} but not an observer for {{Supplier<String>}}.

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list