[cdi-dev] Type variable check for Event.select() and Event.fire()
Matej Novotny
manovotn at redhat.com
Tue Feb 23 10:05:38 EST 2016
Hi, tossing my 0.02$ in.
I believe that anything you cannot boil down to a specific class during type var. resolution should result in exception.
E.g. regarding your questions:
> 1. Event.select()
> ... if you pass a raw type like List.class?
Type variable, as in any other case where you have a MyClass<T>. As long as you do not define T, you have a type variable in place.
>"event.select(new TypeLiteral<List<?>>() {})"
Same scenario I think. I probably fail to see any real difference here? (correct me please ;)
> 2. Event.fire()
> To my understanding:...
My understanding is the same.
Actually this brings it down to the very same problem as in Event.select(), on requirement on type variable are pretty much the same for select() and fire().
> 3. Example snippet
IMHO the snippet SHOULD FAIL as soon as it hits select() method. Relaxing the conditions on select() doesn't make much sense to me for it should fail with the very same problem
on fire(), right?
BTW I am curious, what would the above snippet do in OWB?
One more note:
Be it one way or the other, the terms "to contain a type variable" and "unresolvable type variable" could use a clarification in the spec.
Matej
----- Original Message -----
From: "Martin Kouba" <mkouba at redhat.com>
To: "cdi-dev" <cdi-dev at lists.jboss.org>
Sent: Tuesday, February 23, 2016 9:14:46 AM
Subject: [cdi-dev] Type variable check for Event.select() and Event.fire()
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?
@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);
}
Thanks,
Martin
_______________________________________________
cdi-dev mailing list
cdi-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/cdi-dev
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
More information about the cdi-dev
mailing list