参数顺序 - 覆盖

DRa*_*lav 2 java

根据javadoc

子类中具有相同签名(名称,加上其参数的数量和类型)和返回类型作为超类中的实例方法的实例方法会覆盖超类的方法.

我的问题是 - 参数的顺序是无关紧要的吗?如果它们有相同的名称,它们也是同一类型?

Kep*_*pil 5

顺序很重要,因此具有不同顺序的相同参数的两个方法不被视为具有相同的签名.
例如,此示例不编译:

interface Foo {
    void doIt(String what, int times);
}

class Bar implements Foo {
    public void doIt(int times, String what) {}
}
Run Code Online (Sandbox Code Playgroud)

然而,参数的名称是无关紧要的.这很好:

interface Foo {
    void doIt(String what, int times);
}

class Bar implements Foo {
    public void doIt(String andNowForSomeThingCompetelyDifferent, int theLarch) {}
}
Run Code Online (Sandbox Code Playgroud)