Community
Participate
Working Groups
The basic problem is that when building the varargs for A... args where A has been specified as String, the compiler is ignoring the specified type and building an array of Objects instead. Note that this behaviour has been introduced since at least Eclipse 3.1rc1. This causes a ClassCastException in the following code: public class MyTest { public static void main(String[] args) { Test<String> t = new Tester(); t.method("1st string"); } static abstract class Test<A> { abstract void method(A... args); } static class Tester extends Test<String> { void method(String... args) { System.out.println(args); call(args); } void call(String[] args) { for ( String str : args ) System.out.println("String: "+str); } } } the exact output when compiled with Eclipse 3.1 is: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; at MyTest$Tester.method(MyTest.java:1) at MyTest.main(MyTest.java:10) when compiled using Eclipse 3.1rc1, or javac from Sun's JDK1.5.0_01 the output is as I would expect: [Ljava.lang.String;@360be0 String: 1st string I don't know which is the "correct" result, but if the latest Eclipse is then I would expect a compiler warning or error, rather than a run-time ClassCastException.
*** Bug 102278 has been marked as a duplicate of this bug. ***
Added VarargsTest#test031. Problem comes from the fact the original method is used instead of parameterized one for retrieving the varargs array type. Test<String> -> method(String...) -> original: method(A...) -> arg leaftype: A -> erasure(): Object. It should simply erase the substituted argument: String -> String Fixed
Fixed
Verified in 3.2 M1 with build I20050808-2000.
*** Bug 108095 has been marked as a duplicate of this bug. ***
Verified using M20050923-1430 for 3.1.1