What code and how does java.lang.reflect.Array cre

2019-05-08 02:40发布

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

2条回答
小情绪 Triste *
2楼-- · 2019-05-08 03:09

This is a native method.

That means it's implemented by native code within the JRE.

查看更多
手持菜刀,她持情操
3楼-- · 2019-05-08 03:12

It is hard-coded into the JVM (not the compiler). You could download the source code of OpenJDK or any other open-source Java Virtual Machine and look there ;)

查看更多
登录 后发表回答