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

后端 未结 5 2218
-上瘾入骨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 03:09

    arrayList1 is really a List of size one.

    http://ideone.com/w0b1vY

    arrayList1.size() = 1
    arrayList3.size() = 7
    

    The int[] is being cast to a single Object. That Object cannot be cast to Integer.

提交回复
热议问题