[cdi-dev] [JBoss JIRA] (CDI-475) Support type annotation in assignability of parameterized types

Antonin Stefanutti (JIRA) issues at jboss.org
Mon Oct 6 05:28:12 EDT 2014


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

Antonin Stefanutti commented on CDI-475:
----------------------------------------

Hi Jozef,

In the provided use case, the event is delivered to the {{@Observes ProcessAnnotatedType<@ContextName ? extends CamelContext>}} method for the {{CamelContext}} type being annotated with the {{@ContextName}} annotation at the class level only. That differs from the semantic provided by the {{@WithAnnotations}} which meets another need.

In that perspective, that story is broader than CDI-472 and can be applied to other lifecycle events, e.g.:
{code}
<X> void processManagedBean(@Observes ProcessManagedBean<@MyQualifier X>){}
{code}
where the {{ProcessManagedBean}} would be delivered for every managed bean of type {{X}} qualified with the {{@MyQualifier}} qualifier.

Besides the semantic of type annotations for parameterized type assignability in the typesafe resolution mechanism has to be assessed, for example:
{code}
@Produces
List<@MyAnnotation MyType> producer(){}

@Inject
List<@MyAnnotation MyType> list;
{code}

These are just ideas that should be elaborated in the [Java SE 8 enhancement workshop|https://docs.google.com/document/d/1KUaxXIXJ_r-h5UJGIij6I4vrLS7uXkeeeZr2SaRipWQ].

Hope that clarifies at least in what way that differs from CDI-472.

> Support type annotation in assignability of parameterized types
> ---------------------------------------------------------------
>
>                 Key: CDI-475
>                 URL: https://issues.jboss.org/browse/CDI-475
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Resolution
>            Reporter: Antonin Stefanutti
>
> Since Java 8 provides support for type annotations, the assignability of parameterized types rules could be updated to support that feature that may add value in a number of use cases.
> For example, with lifecycle events resolution, instead of writing:
> {code}
> Set<Annotation> contextNames = new HashSet<>();
> void camelContextNames(@Observes ProcessAnnotatedType<? extends CamelContext> pat) {
>     if (pat.getAnnotatedType().isAnnotationPresent(ContextName.class))
>         contextNames.add(pat.getAnnotatedType().getAnnotation(ContextName.class));
> }
> {code}
> One could directly write:
> {code}
> void camelContextNames(@Observes ProcessAnnotatedType<@ContextName ? extends CamelContext> pat) {
>     contextNames.add(pat.getAnnotatedType().getAnnotation(ContextName.class));
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the cdi-dev mailing list