我是Java的新手,但我理解基础知识。我知道接口是抽象类,它们用于模拟多重继承(类 - 我知道在Java中这是不允许的)。我有这个代码;你能解释一下吗?使用类和接口的代码
这里是遍历的类的列表的方法的一部分:
Constructor[] c = aClass.getConstructors();
for (Constructor constructor : c) {
if (constructor.getParameterTypes().length == 0) {
AInterface action = (AInterface) constructor.newInstance();
try {
action.run(request, response);
}
}
}
下面是由上述代码中使用的接口定义:
public interface AInterface
{
void run(HttpServletRequest request, HttpServletResponse response);
}
您尚未明确指出您的问题,但我可以告诉您接口与抽象类不同。 – Mike 2009-10-02 22:39:40
http://mindprod.com/jgloss/interfacevsabstract。html – Mike 2009-10-02 22:40:20
看起来像一些疯狂的Command模式代表团。对于某个java新手来说,这是一个相当粗糙的问题。 – 2009-10-02 22:41:41