我正在研究Java 8文档ArrayList.我得到的最大数组大小定义为Integer.MAX_VALUE - 8平均值2 ^ 31 - 8 = 2 147 483 639.然后,我的重点是,为什么8减去或why not less than 8或more than 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;
Run Code Online (Sandbox Code Playgroud)
我得到了一些相关的答案,但没有实现我的目标.
有些人根据文档给出了一些逻辑"Some …