-
Bug
-
Resolution: Not a Bug
-
Minor
-
None
-
3.1.3.Final
-
None
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:
@Inject private Cloneable foo;
And a producer method like this:
@Produces private static Integer[] makeIntegers() { return new Integer[]{42}; }
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.
Cloneable.class.isAssignableFrom(Integer[].class) returns true because the JLS says it must.