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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With