Is it possible to use type variance in CDI events? here is the case:
- Suppose i have a root event type
MyEvent
and subclassDummyEvent
- My goal is to process a list of events received from a remote source
List<? extends MyEvent>
, containingDummyEvent
instances
How can i do this?
If i loop through the collection calling fire()
on each event, it will invoke @Observes MyEvent evt
but not @Observes DummyEvent evt
methods.
** update **
Created a sample code to clarify the issue:
https://github.com/jfaerman/jfaerman/blob/master/test-cdi/src/main/java/jfaerman/App.java
I would like the event to be fired twice, one time individually and one time from the list.
It works injecting the BeanManager instad of Event, as tested by this servlet:
https://github.com/jfaerman/cdi-tests/blob/master/src/main/java/jfaerman/TestEventsServlet.java
Answered by Jozef Hartinger in this thread in the Weld forum:
https://community.jboss.org/message/716185