[cdi-dev] Type variable check for Event.select() and Event.fire()

Martin Kouba mkouba at redhat.com
Tue Feb 23 03:14:46 EST 2016

Hi all,

I'd like to discuss the following two sentences taken from "10.2.1. The 
Event interface").

1. Event.select()

"If the specified type contains a type variable, an 
IllegalArgumentException is thrown."

So what should happen if you pass a raw type like List.class? The 
Class.getTypeParameters() method returns [E]. Does it mean the type 
contains a type variable? And what about "event.select(new 
TypeLiteral<List<?>>() {})"?

2. Event.fire()

"If the runtime type of the event object contains an unresolvable type 
variable, an IllegalArgumentException is thrown."

To my understanding:
1. the runtime type = eventPayload.getClass()
2. get type variables = getTypeParameters()
3. unresolvable = it's not possible to resolve the variable, nor from 
the Event injetion point nor from the selected type (Event.select()), 
anything else?

3. Example snippet

Should the following snippet fail or not? It currently fails in Weld 
during event.select(). But even if we relax the check it will not be 
always possible to resolve all the type variables, i.e. the subsequent 
{{fire()}} invocation might fail. Or am I missing anything?

Event<Object> event;
public void testSelectSubtypeWithWildcard() {
   List<String> updatedList = new ArrayList<>();
   Event<List<?>> child = event.select(new TypeLiteral<List<?>>() {});



More information about the cdi-dev mailing list