What code and how java.lang.reflect.Array creates a new array at runtime?

I looked at the Java source code and the method is as 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 doesn't seem to have code in the newArray() method to build the array. Can someone explain how it creates an array? T

+4
source share
2 answers

This is the native method.

This means that it is implemented using native code in the JRE.

+5
source

It is hardcoded in the JVM (not the compiler). You can download the source code of OpenJDK or any other open source Java virtual machine and see there;)

+1
source

Source: https://habr.com/ru/post/1493022/


All Articles