Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 882
sp00m Avatar asked Feb 12 '13 16:02

sp00m


1 Answers

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.

like image 90
assylias Avatar answered Oct 12 '22 20:10

assylias