T
tam
According to the JLS clone is a public method for all array types:
6.4.5 Members of an Array Type
....
The public method clone, which overrides the method of the same name
in class Object and throws no checked exceptions. The return type of
the clone method of an array type T[] is T[].
....
However if I run the following program (JDK 1.5.0_04-b05 on Linux):
import java.lang.reflect.*;
public class Test {
public static void main(String[] args) {
int[] x = {1,2,3};
System.out.println("Class:"+x.getClass());
Class cls = x.getClass();
Method[] methods= cls.getMethods();
for(Method meth: methods) {
System.out.println("Method:"+meth);
}
}
}
I get the output
Class:class [I
Methodublic native int java.lang.Object.hashCode()
Methodublic final native java.lang.Class
java.lang.Object.getClass()
Methodublic final native void java.lang.Object.wait(long) throws
java.lang.InterruptedException
Methodublic final void java.lang.Object.wait(long,int) throws
java.lang.InterruptedException
Methodublic fina lean java.lang.Object.equals(java.lang.Object)
Methodublic final native void java.lang.Object.notify()
Methodublic final native void java.lang.Object.notifyAll()
Methodublic java.lang.String java.lang.Object.toString()
The clone method is missing.
The JavaDocs for the Class.getMethods is:
Returns an array containing Method objects reflecting all the public
member methods of the class or interface represented by this Class
object, including those declared by the class or interface and those
inherited from superclasses and superinterfaces.
So I should have gotten all the public methods, and clone is supposed
to be public, but it's
not showing up.... Does anyone have any idea what I'm missing?
Regards,
Tom McGlynn
6.4.5 Members of an Array Type
....
The public method clone, which overrides the method of the same name
in class Object and throws no checked exceptions. The return type of
the clone method of an array type T[] is T[].
....
However if I run the following program (JDK 1.5.0_04-b05 on Linux):
import java.lang.reflect.*;
public class Test {
public static void main(String[] args) {
int[] x = {1,2,3};
System.out.println("Class:"+x.getClass());
Class cls = x.getClass();
Method[] methods= cls.getMethods();
for(Method meth: methods) {
System.out.println("Method:"+meth);
}
}
}
I get the output
Class:class [I
Methodublic native int java.lang.Object.hashCode()
Methodublic final native java.lang.Class
java.lang.Object.getClass()
Methodublic final native void java.lang.Object.wait(long) throws
java.lang.InterruptedException
Methodublic final void java.lang.Object.wait(long,int) throws
java.lang.InterruptedException
Methodublic fina lean java.lang.Object.equals(java.lang.Object)
Methodublic final native void java.lang.Object.notify()
Methodublic final native void java.lang.Object.notifyAll()
Methodublic java.lang.String java.lang.Object.toString()
The clone method is missing.
The JavaDocs for the Class.getMethods is:
Returns an array containing Method objects reflecting all the public
member methods of the class or interface represented by this Class
object, including those declared by the class or interface and those
inherited from superclasses and superinterfaces.
So I should have gotten all the public methods, and clone is supposed
to be public, but it's
not showing up.... Does anyone have any idea what I'm missing?
Regards,
Tom McGlynn