【发布时间】:2013-11-14 06:37:08
【问题描述】:
在外部类中有一个内部接口、一个内部抽象类和一个内部类。
当我调用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.
}
}
}
提前谢谢你。
【问题讨论】:
-
“不能打印任何东西”是什么意思?目前还不清楚出了什么问题。
-
@JonSkeet 有了接口、类和抽象类的深度嵌套,这似乎不是设计问题吗? =)
-
@LittleChild:这远非理想,但我想知道 OP 遇到的问题并先解决它,然后再解决其他所有问题......
-
这甚至无法编译,
prinfln不存在,input在抽象类中未定义,preExec 等也采用 1 个参数而不是 2.. -
你在单个参数 inputList 中调用所有函数。但是你的 all 函数有 2 个参数。
标签: java reference abstract inner-classes