Why does Java ArrayList use per-element casting instead of per-array casting?
- by user1111929
What happens inside Java's ArrayList<T> (and probably many other classes) is that there is an internal Object[] array = new Object[n];, to which T Objects are written. Whenever an element is read from it, a cast return (T) array[i]; is done. So, a cast on every single read.
I wonder why this is done. To me, it seems like they're just doing…