In quest of source code: where is the clone() method of arrays implemented? [closed]

我的梦境 提交于 2019-12-14 00:47:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!