Why java does not autobox int[] to Integer[]

后端 未结 5 2209
-上瘾入骨i
-上瘾入骨i 2020-12-16 02:45

When I do the following,

  • arrayList1 - contains one element and it is an int[].
  • arrayList2 - not compiling (Err
5条回答
  •  死守一世寂寞
    2020-12-16 02:59

    Because int[] and Integer[] both are objects. First will hold primitive int values, which are not of type Object while second will store references of Integer objects, which are of type Object.

提交回复
热议问题