什么代码以及java.lang.reflect.Array在运行时如何创建新数组?

rol*_*luo 4 java arrays reflection

我研究了Java源代码,方法如下:

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;
Run Code Online (Sandbox Code Playgroud)

它似乎在newArray()构建数组的方法中没有任何代码.任何人都可以解释它是如何构建数组的?Ť

SLa*_*aks 5

这是一种native方法.

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