如何從超類方法獲取對子類的引用?從超類獲取子類的類引用
例如,
public class MySuper {
public void myMethod(){
// here i need a reference to MySub1.class or MySub2.class
// depending on the class of the instance that invoked this method
}
}
public class MySub1 extends MySuper {
public String myString;
}
public class MySub2 extends MySuper {
public int myInt;
}
對象是否已經初始化,或者我們需要初始化對象,當我們收到參數時。 –