Community
Participate
Working Groups
As demonstrated with the below test case, passing an subclass array to a method that takes a vararg parameter of the parent class causes Eclipse to print out a warning that you need an explicit cast. However, when adding an explicit cast, Eclipse prints out a warning that the cast is redundant. public class VarargsTest extends TestCase { public void testPassingSubclassArrayAsVararg() { // The argument of type VarargsTest.Subclass[] should explicitly be // cast to VarargsTest.Parent[] for the invocation of the varargs // method processVararg(VarargsTest.Parent...) from type VarargsTest. // It could alternatively be cast to VarargsTest.Parent for a varargs // invocation processVararg(new Subclass[] {}); } public void testPassingSubclassArrayAsVarargWithCast() { // Unnecessary cast from VarargsTest.Subclass[] to // VarargsTest.Parent[] processVararg((Parent[]) new Subclass[] {}); } private void processVararg(Parent... objs) { } class Parent { } class Subclass extends Parent { } }
The warning requiring explicit cast should not appear. This was resolved a while ago; now you can safely remove the unnecessary cast. Worksforme. Added VarargsTest#test058