[cdi-dev] [JBoss JIRA] (CDI-169) Remove the 'No type variable in event objects' restriction

Martin Kouba (Commented) (JIRA) jira-events at lists.jboss.org
Thu Nov 3 11:09:45 EDT 2011


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

Martin Kouba commented on CDI-169:
----------------------------------

Not a good example I think. In this situation it is possible. Event knows its InjectionPoint that knows its java.lang.reflect.Member (Field in this case). Following pseudocode will work.
{code} 
Field field = (Field) injectionPoint.getMember();
Type eventType = field.getGenericType();

if(eventType instanceof ParameterizedType) {

  for(Type eventTypeArgument : ((ParameterizedType) eventType).getActualTypeArguments()){
   // Now at Event level

   if(eventTypeArgument instanceof ParameterizedType) {
     for (Type fooTypeArgument : ((ParameterizedType) eventTypeArgument).getActualTypeArguments())
     {
      // Now at Foo level
      System.out.println("fooTypeArgument = " + fooTypeArgument);
     }
    }
  }
}
{code}

See http://tutorials.jenkov.com/java-reflection/generics.html

However in this situation it is *NOT* possible...

{code}
class Bar {

  @Inject
  BeanManager beanManager;

  public void fire() {
    beanManager.fireEvent(new Foo<Baz>());
  }

}
{code}

                
> Remove the 'No type variable in event objects' restriction
> ----------------------------------------------------------
>
>                 Key: CDI-169
>                 URL: https://issues.jboss.org/browse/CDI-169
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>    Affects Versions: 1.0
>            Reporter: Stuart Douglas
>             Fix For: 1.1 (Proposed)
>
>
> CDI 10.1 states:
> An event object is an instance of a concrete Java class with no type variables. ... An event type may not contain a type variable.
> Which seems silly considering the container fires events with a type variable at startup. I can't think of any reason why this should be prohibited. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the cdi-dev mailing list