I am not sure whether this is a bug or a feature enhancement.
When a bean of any kind reports its type closure, it ends up doing so using its {{getTypeClosure()}} method. The CDI specification says somewhere in section 11.4:
"{{getTypeClosure()}} returns all types *to which the base type should be considered assignable*."
Note the very careful wording here: it doesn't mention superclasses or interfaces, just assignability.
Now consider an injection point like this: {code} @Inject private Cloneable foo; {code} And a producer method like this: {code} @Produces private static Integer[] makeIntegers() { return new Integer[]{42}; } {code} *Leaving aside whether this would be ambiguous* (this would be a truly stupid injection point), should the producer method's return type ({{Integer[].class}}, one of its bean types) be considered assignable to an injection point of type {{Cloneable}}?
Or, more precisely, should the return value of the producer method's {{Bean}} implementation's {{getTypeClosure()}} method include {{Cloneable}} (and {{Serializable}})?
I think it should.
An array type does not have {{Cloneable }} in its superclass hierarchy (obviously) or its implemented interfaces, but {{Cloneable .class.isAssignableFrom(Integer[].class)}} returns {{true}} because the JLS [says it must|https://docs.oracle.com/javase/specs/jls/se13/html/jls-4.html#jls-4.10.3]. |
|