The CDI 4.0 spec says in section 2.8.1 (https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#event_types_and_qualifier_types):
"Any Java type may be an observed event type."
That means I can do this:
private void primitive(@Observes int i) { // any type, including int, can be an observed event type
System.out.println("primitive: " + i);
}
And this:
private void wrapper(@Observes Integer i) {
System.out.println("wrapper: " + i);
}
Then of course the only way to fire an event is by using the Event object and specifying the type of even you want to fire as its sole type argument:
// for example
@Inject
private Event<Integer> e;
(Type arguments of course cannot be primitive.)
No mention in the specification's section on observer resolution talks about primitive types and/or wrapper types and how they interact. (Obviously there are unrelated sections regarding typesafe resolution in the context of dependency injection that do talk about this, but they do not seem to apply here without a biiiiiig stretch (observed event parameters are not injection points; event types are not bean types).)
If I do e.fire(Integer.valueOf(42)), the primitive(int) observer method above is called (in Weld 5.1.3.Final). So is the wrapper(Integer) observer method. This certainly is convenient and I'm kind of glad it works that way, but is it correct? Is it a Weld value-add? Or should the spec have said something about interoperability of primitives and wrapper types in observer resolution?
Best,
Laird