[英]How can I use the reference parameter of the inner abstract class in JAVA
外部類中有一個內部接口,一個內部抽象類和一個內部類。
當我調用OuterClass的outerMethod()方法時,
AKindBiz 類的方法只能打印列表的內容。
為什么抽象類(CommonKindBiz)的方法不能打印任何東西?
public class OuterClass {
public void outerMethod( ) throws Exception{
ArrayList<String> list = new ArrayList<String>();
list.add("1111");
list.add("2222");
KindBiz biz = new AKindBiz();
biz.execute(list);
}
public interface KindBiz
{
public void execute( ArrayList<String> inputList) throws Exception;
public void preExec( ArrayList<String> inputList) throws Exception;
public void exec( ArrayList<String> inputList) throws Exception;
public void postExec( ArrayList<String> inputList) throws Exception;
}
abstract public class CommonKindBiz implements KindBiz
{
public void execute( ArrayList<String> inputList) throws Exception{
System.out.println("KindBiz.CommonKindBiz.execute ### inputList1 : " + inputList ); // Nothing printed.
this.preExec(inputList);
this.exec(inputList);
this.postExec(inputList);
}
public void preExec( ArrayList<String> inputList) throws Exception
{
System.out.println("KindBiz.CommonKindBiz.preExec ### inputList : " + inputList ); // Nothing printed.
}
public abstract void exec( ArrayList<String> inputList) throws Exception;
public void postExec( ArrayList<String> inputList) throws Exception
{
System.out.println("KindBiz.CommonKindBiz.postExec ### inputList : " + inputList ); // Nothing printed.
}
}
public class AKindBiz extends CommonKindBiz
{
@Override
public void exec( ArrayList<String> inputList) throws Exception
{
System.out.println("KindBiz.AKindBiz.exec ### inputList : " + inputList ); // "1111", "2222" printed.
}
}
}
先感謝您。
System.out.prinfln("KindBiz.CommonKindBiz.execute ### inputList1 : " + inputList ); // Nothing printed.
那條線似乎是問題所在。 它是println()
。 在您的代碼中,到處都有prinfln()
。 用println()
替換它們
更新:
正如 RC 和 subash 指出的那樣,您的方法聲明它們將采用 2 個參數,但在調用它們時只給它們 1 個。 您需要給他們 2 或更改您的方法的簽名。
請使用IDE。 這些錯誤(如參數不匹配)可以很容易地被 IDE 指出,並正確描述錯誤的內容以及如何修復它們。
我編輯了您的代碼以使其編譯。
我測試了一下,所有的行都打印出來了。 我不相信有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.