私は、これらのインタフェースとクラスを持っている:同じメソッドを持つ抽象クラスとinheretingサブクラスで、異なる型引数を取得して使用しますか?
public interface AlternateLight {
public String change(long time);
}
public abstract class AbstractLight {
public String change(int time) {
return "AbstractLight Method was used";
}
}
public class DistinctAlternateLight extends AbstractLight implements AlternateLight {
public String change(long time) {
return "DistinctAlternateLight Method was used";
}
}
は、今私は、主に以下のメソッドを持つ方法変更()を呼び出し:
public class WhatUsedTest {
public static void main(String[] args) {
AlternateLight al = new DistinctAlternateLight();
System.out.println(al.change(100));
}
}
それは「DistinctAlternateLightメソッドを使用した」印刷しますが、なぜですか?引数として100の後ろに "L"を置かなかったので、抽象クラスのメソッドは整数を取るため、抽象クラスのメソッドを呼び出します。 "L"を抜けて、コンパイラは100を長い値として処理せず、longを取るメソッドを呼び出すと推測しましたが、そうしています。どうしてこんなことに?