[cdi-dev] [JBoss JIRA] (CDI-448) Clarify autoboxing of arrays

Jozef Hartinger (JIRA) issues at jboss.org
Fri Jul 4 06:47:24 EDT 2014

Jozef Hartinger created CDI-448:

             Summary: Clarify autoboxing of arrays
                 Key: CDI-448
                 URL: https://issues.jboss.org/browse/CDI-448
             Project: CDI Specification Issues
          Issue Type: Clarification
    Affects Versions: 1.2.Final
            Reporter: Jozef Hartinger

Section 2.2.1:

• A bean type may be an array type. Two array types are considered identical only if the element type is identical.
• A bean type may be a primitive type. Primitive types are considered to be identical to their corresponding wrapper types in java.lang.

When these two rules are combined, autoboxing of arrays is implied. For example, having type A defined as int[] and type B defined as Integer[] then:
1) these two array types are considered identical as long as their element types (int and Integer) are identical
2) int and Integer are considered identical (as primitive types are considered identical to java.lang wrapper types)

Thus, A and B are considered identical.

This is however in contrast to JLS where array autoboxing is not supported - you cannot do int[] foo = new Integer[0];

It should therefore be clarified if array autoboxing is also unsupported in CDI or whether a CDI implementation should do the extra work to support this (e.g. allocating a new array and copying autboxed values over before injecting)

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list