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

2
  • 5
    It's pretty much hardcoded into Java, or in other words, it uses black magic. Commented Jul 23, 2013 at 17:36
  • native methods delegate to C code. Commented Jul 23, 2013 at 17:37

2 Answers 2

5

This is a native method.

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

1

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 ;)

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.