Bug 83379 - [1.5] compiler does not warn when overriding methods with parameters as array and vararg
Summary: [1.5] compiler does not warn when overriding methods with parameters as array...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 trivial (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-21 06:21 EST by Markus Keller CLA
Modified: 2005-02-16 07:46 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 Markus Keller CLA 2005-01-21 06:21:20 EST
I20050118-1015

The compiler allows to override a method with an array parameter by a method
with a vararg parameter.

In contrast, javac says:
- warning: runall(java.lang.Runnable...) in p.Sub cannot override
runall(java.lang.Runnable[]) in p.Top; overridden method has no '...'
- warning: runall(java.lang.Runnable[]) in p.Sub2 cannot override
runall(java.lang.Runnable...) in p.Sub; overriding method is missing '...'

However, both compilers create classfiles in which the methods do override.

------------------------------------------------
package p;

public class A {
    public static void main(String[] args) {
        Runnable r1 = null, r2 = null;
        System.out.println(new Top().runall(new Runnable[] { r1, r2 }));
        System.out.println(new Sub().runall(new Runnable[] { r1, r2 }));
        System.out.println(new Sub().runall(r1, r2));
        System.out.println(new Sub2().runall(new Runnable[] { r1, r2 }));
    }
}

class Top {
    public String runall(Runnable[] runnables) {
        return "Top";
    }
}

class Sub extends Top {
    public String runall(Runnable... runnables) {
        return "Sub, " + super.runall(runnables);
    }
}

class Sub2 extends Sub {
    public String runall(Runnable[] runnables) {
        return "Sub2, " + super.runall(runnables);
    }
}
Comment 1 Kent Johnson CLA 2005-02-07 15:18:56 EST
See VarargsTest test011
Comment 2 David Audel CLA 2005-02-16 07:46:16 EST
Verified in I20050215-2300