これがその名前かどうかはわかりませんが、ここに問題があります。
3 つのサブクラスを持つスーパークラスがあります。スーパークラス、サブクラス1、サブクラス2、サブクラス3としましょう
次のオーバーロードされたメソッドを持つ別のクラスがあります。
public void exampleMethod (Subclass1 object1){
//Method to be called if the object is of subclass 1
}
public void exampleMethod (Subclass2 object2){
//Method to be called if the object is of subclass 2
}
public void exampleMethod (Subclass3 object3){
//Method to be called if the object is of subclass 3
}
実行時にメソッド パラメータをオブジェクト型に動的にキャストしながら、オーバーロードされたメソッドをスーパークラスから呼び出す方法はありますか?
anotherClass.exampleMethod(this);