4

I looked into Java source code and the method is like follows:

public static Object newInstance(Class<?> componentType, int length)
    throws NegativeArraySizeException {
    return newArray(componentType, length);
}

private static native Object newArray(Class componentType, int length)
    throws NegativeArraySizeException;

It seems it does not have any code in the method newArray() to build an array. Can anyone explain how it builds an array? T

4

2 回答 2

5

这是一种native方法。

这意味着它是由 JRE 中的本机代码实现的。

于 2013-07-23T17:38:02.147 回答
1

它被硬编码到 JVM(而不是编译器)中。您可以下载 OpenJDK 或任何其他开源 Java 虚拟机的源代码并查看那里;)

于 2013-07-23T17:38:04.817 回答