Hi all,
This follows up on my last message to cdi-dev: "Type variable check for
Event.select() and Event.fire()".
After I spend some time searching I have to rephrase the question:
Should a wildcard type be considered an unresolved type variable or not?
Of course, in the scope of events. I believe the spec is not clear here.
See also "10.1. Event types and qualifier types" and "10.2.1. The Event
interface".
There is CDI-494 which assumes a wildcard type _is_ an unresolved type
variable [1].
From the TCK point of view - there is only
FireEventTest.testTypeVariableEventTypeFails() which assumes that a type
variable resolved to a wildcard (inferred from the Event injection
point) is unresolvable - see also CDITCK-510 [2].
Note that in CDI 1.0 the container cannot use the Event specified type
to infer the parameterized type.
The current behavior
====================
Weld 1 allows to pass a wildcard to Event.select() but Event.fire() is
problematic (e.g. the snippet [3] does fail).
Weld 2+ is imho overly strict here and throws IllegalArgumentException
whenever a type variable is resolved to a wildcard type (Event.select(),
Event.fire()).
The latest OWB seems to support this, but it does not always infer the
parameterized type consistently (e.g. the TCK test mentioned above is
passing even if it's possible to resolve the type variable to the
wildcard type).
Clarification
=============
I'm no expert on generics but I think we shouldn't treat wildcard types
as unresolved type variables, i.e. reject CDI-494 and clarify the
snippet [3] and similar should work. At least I cannot see any problem.
But maybe I'm missing somethig.
Thanks for feedback,
Martin
[1]
https://issues.jboss.org/browse/CDI-494
[2]
https://issues.jboss.org/browse/CDITCK-510
[3]
@Inject
Event<Object> event;
public void testSelectSubtypeWithWildcard() {
List<String> updatedList = new ArrayList<>();
updatedList.add("foo");
Event<List<?>> child = event.select(new TypeLiteral<List<?>>()
{});
child.fire(updatedList);
}