Duplicate :
|
According to JLS 10.7, every array type has a public clone() method. The spec for Class.getMethod() clearly requires such a public method to be returned. Yet this clone() method is never returned from Class.getMethod(). ==========$ cat -n Test.java 1 class Test { 2 public static void main(String[] args) throws Exception { 3 Object argsClone = args.getClass().getMethod("clone").invoke(args); 4 System.out.println("args = " + args.hashCode()); 5 System.out.println("args = " + argsClone.hashCode()); 6 } 7 } ==========$ /java/re/j2se/1.5.0/promoted/latest/binaries/`platform`/bin/java -version java version "1.5.0-beta2" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51) Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode) ==========$ /java/re/j2se/1.5.0/promoted/latest/binaries/`platform`/bin/javac Test.java ==========$ /java/re/j2se/1.5.0/promoted/latest/binaries/`platform`/bin/java Test Exception in thread "main" java.lang.NoSuchMethodException: [Ljava.lang.String;.clone() at java.lang.Class.getMethod(Class.java:1386) at Test.main(Test.java:3) ==========$