Why does Java ArrayList use per-element casting instead of per-array casting?

前端 未结 4 690
梦如初夏
梦如初夏 2021-01-07 18:47

What happens inside Java\'s ArrayList (and probably many other classes) is that there is an internal Object[] array = new Object[n];, to w

4条回答
  •  轮回少年
    2021-01-07 19:21

    Array is object too. Here T[] array = (T[]) new Object[n] you cast only (T[]) object type not elements in the array.

提交回复
热议问题