引数が違うが同じような動作をする場合、に限ってメソッドをオーバーロードすべし。静的か動的かよく忘れる……
class A{
}
class B extends A{
}
class C {
test(A x){
System.out.println("A");
}
test(B x){
System.out.println("B");
}
public static void main(String[] args){
// 実体がBのインスタンスであろうと
// test(A x)が呼ばれる
A x = new B();
new C().test(x);
}
}
参考: Java用語集 オーバーロード
tags: Java zurazure
Posted by NI-Lab. (@nilab)

