刚才在看AbstractCollection的源码,里面有个MAX_ARRAY_SIZE定义为Integer.MAX_VALUE - 8,突然好奇为什么要减8呢,是因为一些虚拟机要保存一些标题之类的东西在数组里的原因吗?
源码如下:
/**
* The maximum size of array to allocate.* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may result in
* OutOfMemoryError: Requested array size exceeds VM limit
*/
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;