问题
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 Ctrl-clicking on it (as usual), but it brought me to the Object's native one, which provides only the signature and not the body of the method.
The autocomplete told me that the said clone() method belonged to the String class (clone() : String[] - String), but the source code of the String class doesn't provide such a method (since I'm dealing with the String[] class...).
So, where is that implementation hiding? Should the autocomplete be fixed?
回答1:
The code for cloning an array is in the JVM (it is a native method). For hotspot, it is around lines 550/560 of jvm.cpp.
回答2:
What is confusing is that Eclipse says that the clone method for a String array is in String class. But the length method of String array is from String[].
来源:https://stackoverflow.com/questions/14837139/in-quest-of-source-code-where-is-the-clone-method-of-arrays-implemented