Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
5  
It's pretty much hardcoded into Java, or in other words, it uses black magic. –  Louis Wasserman Jul 23 '13 at 17:36
    
native methods delegate to C code. –  Sotirios Delimanolis Jul 23 '13 at 17:37

2 Answers 2

up vote 5 down vote accepted

This is a native method.

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

share|improve this answer

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

share|improve this answer
2  
Any idea where to look? –  SLaks Jul 23 '13 at 17:38
    
    
Then go here: hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/… - at this point, you should realize that this is intimately connected to the JVM internals and there's really no point in trying to understand the code. –  Sebastian Redl Jul 23 '13 at 17:57
    
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.