Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] History of/rationale for type closure rules for producer method return types?

Hi,

It's probably because at that time, when this rule was added into CDI 1.0, Java 6 was the latest version. And Javadoc of Java 6 doesn't say anything about interfaces of arrays: https://javadoc.scijava.org/Java6/java/lang/Class.html#getInterfaces(). So, it wasn't guaranteed that arrays implement Cloneable and Serializable interfaces. I'm not sure about Number[] but I would say, it's an oversight that the spec doesn't allow this. The superclass returned from Integer[].class.getSuperclass() is Object, not Number[], although the superclass of Integer is Number. It's not easy to find any info about the relationship between Integer[] and Number[] in the official documentation even for Java 21. So I think that the spec made it simple and just didn't allow Number[] as a bean type of Integer[].

To support Cloneable, Serializable, the spec could be improved to specifically mention those interface as the Javadoc for the latest Java does for Class.getInterfaces() method. Or state that a bean has all bean types returned by the Class.getInterfaces(), which would then depend on the version of Java used at runtime.

All the best,
Ondro

On Sat, Aug 3, 2024 at 4:21 AM Laird Nelson via cdi-dev <cdi-dev@xxxxxxxxxxx> wrote:
If you have:

@Produces Integer[] makeIntegerArray() { return new Integer[] { 42 }; }

…the bean types of this bean will be, exactly, {Integer[], Object} (see https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#producer_method_types).

Does anyone know or remember what the rationale is or was for not permitting {Number[], Cloneable, Serializable} to also be automatically part of the bean types set? I'm sure there must have been a good reason.

Best,
Laird

_______________________________________________
cdi-dev mailing list
cdi-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdi-dev

Back to the top