Bug 162171 - [1.5][compiler] Needs explicit cast / unnecessary cast confusion with varargs
Summary: [1.5][compiler] Needs explicit cast / unnecessary cast confusion with varargs
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-25 03:38 EDT by Pekka Enberg CLA
Modified: 2007-02-06 06:28 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pekka Enberg CLA 2006-10-25 03:38:21 EDT
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 {
    }
}
Comment 1 Philipe Mulet CLA 2007-01-10 07:50:17 EST
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