Why it's impossible to create an array of MAX_INT size in Java?

前端 未结 2 1954
醉梦人生
醉梦人生 2021-02-06 14:57

I have read some answers for this question(Why I can't create an array with large size? and https://bugs.openjdk.java.net/browse/JDK-8029587) and I don\'t understand the fol

2条回答
  •  没有蜡笔的小新
    2021-02-06 15:17

    Only addressing the why arrays of different types have the same limit on max count of elements? part:

    Because it doesn't matter to much in practical reality; but allows the code implementing the JVM to be simpler.

    When there is only one limit; that is the same for all kinds of arrays; then you can deal all arrays with that code. Instead of having a lot of type-specific code.

    And given the fact that the people that need "large" arrays can still create them; and only those that need really really large arrays are impacted; why spent that effort?

提交回复
热议问题