public abstract class AbstractClass
{
public abstract void AbstractClassMethod();
}
public class DerivedClass extends AbstractClass {
@Override
public void AbstractClassMethod() {
// TODO Auto-generated method stub
}
}
public interface InterfaceObject
{
public void InterfaceObjectMethod(AbstractClass oAbstractClass);
}
public class TestAbstractParam implements InterfaceObject {
@Override
public void InterfaceObjectMethod(AbstractClass oAbstractClass) {
// TODO Auto-generated method stub
}
}
public class TestDerivedParam implements InterfaceObject {
@Override
public void InterfaceObjectMethod(DerivedClass oDerivedClass) {
// TODO Auto-generated method stub
}
}
编译 TestDerivedParam 类时出现错误。谁能解释一下这背后的原因?更具体地说,问题是为什么方法不能接受期望基类型的子类型参数?谢谢!