Looking for source code: where is the clone () array method implemented?

new String[] { "foo", "bar" }.clone(); 

With my favorite IDE (i.e. Eclipse), I wanted to see the source code of the above clone() method by pressing Ctrl (as usual) on it, but it led me to the native Object , which provides only the signature, and not the body of the method.

AutoComplete informed me that the specified clone() method belonged to the String class ( clone() : String[] - String ), but the source code of the String class does not provide such a method (since I am dealing with the String[] class).

So where is this implementation hiding? Should autocomplete be fixed?

+7
source share
2 answers

The code for cloning an array is in the JVM (this is a native method). For the access point, this is near the lines 550/560 jvm.cpp .

+8
source

What is confusing is that Eclipse says that the clone method for the String array is in the String class. But the length method of the String array has a String[] value.

enter image description here

0
source

All Articles