Community
Participate
Working Groups
If a method is generic and has varargs, such as: //////// Fragment 1 ////////// public class Functor<T> { public void func(T... args) { When invoking this method, such as: //////// Fragment 2 ////////// Functor<String> functor = new Functor<String>(); functor.func("Hello!"); The invoker should be compiled as following (with JDK 1.5.0): //////// Fragment 3 ////////// functor.func(new String[] { "Hello!" }); but Eclipse 3.1 JDT compiled it as following: //////// Fragment 4 ////////// functor.func(new Object[] { "Hello!" }); If there's an inner class which overriden this method, such as: //////// Fragment 5 ////////// Functor<String> functor = new Functor<String>() { public void func(String... args) { System.out.println(args.length); } }; it will be compiled with two methods, one is a volatile delegation, another is really functional, as following: //////// Fragment 6 ////////// static class Functor$1 extends Functor { public transient void func(String as[]) { System.out.println(as.length); } public volatile void func(Object aobj[]) { func((String[])aobj); // ClassCastException here } Combine Fragment 4 and Fragment 6, there will be a ClassCastException thrown. Fragment 3 should be correct.
Created attachment 24190 [details] org.groller.functor.Functor.java Source code with main method. Will throw ClassCastException when run in Eclipse 3.1 JDT.
Looks like the same bug as #102181 to me.
*** This bug has been marked as a duplicate of 102181 ***
Added VarargsTest#test032