Haven't seen the right answer, even though it's very easy to test.
In a recent HotSpot VM, the correct answer is Integer.MAX_VALUE - 5
. Once you go beyond that:
public class Foo {
public static void main(String[] args) {
Object[] array = new Object[Integer.MAX_VALUE - 4];
}
}
You get:
Exception in thread "main" java.lang.OutOfMemoryError:
Requested array size exceeds VM limit
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…