可以說我有幾個類,我試圖調用我的超類中的一個方法,並且發生此錯誤。我無法理解爲什麼?在superconstructor被調用之前不能引用'method'
文件1:
public class A extends B {
public A(int arg1){
this(arg1, new class_C(getMethod())); // Throws error here
}
public A(int arg1, int arg2){
super(arg1) ;
}
}
文件2:
public class B{
public B(int arg1){
super(arg1) ;
}
public int getMethod() { return 100;}
}
感謝您的幫助。
如果'getMethod()'可以變成靜態的,那就這樣做。如果不能,這意味着它取決於'this'的狀態,在施工完成之前這是無效的。 – shmosel
B的父類是什麼? – ravthiru