我有一个Java代码,应该在基类的构造函数中调用重写的方法。 我了解根据许多参考资料可能会导致问题,例如:
Calling an overridden method from a parent class ctor
还有
我有问题要改用哪种模式?
在此处添加示例代码是一个Task构造函数:
public <T extends AbstractCommon & IParent> Task(T parent, String uuid, String version, Set<AbstractNode> exceptions) throws Exception {
Event tef = getExecutionFinishedEvent();
Event tep = getExecutionInProgressEvent();
Event tefailed = getExecutionFailed();
Event tefinishedonallnodes = getExecutionFinishedOnAllNodesEvent();
Event tTimeout = getTimeoutEvent();
Event tNotAllNodesAreAcessible = getNotAllNodesAreAccessible();
Event tNotAllObjectsAreAvailable = getNotAllObjectsAreAvailable();
}
这是扩展类AbstractRemoteTask,还有其他一些类。
public abstract class AbstractRemoteTask extends Task implements InterNodeProcessor {
public AbstractRemoteTask() {
}
@JsonIgnore
@Override
protected Event getExecutionFinishedEvent() {
return getEvent(Event.EventType.EXECUTION_FINISHED_LOCAL);
}
@JsonIgnore
@Override
protected Event getExecutionFinishedOnAllNodesEvent() {
return getEvent(Event.EventType.EXECUTION_FINISHED_ON_ALL_NODES);
}
@Override
protected Event getExecutionInProgressEvent() {
return getEvent(Event.EventType.EXECUTION_IN_PROGRESS);
}
@JsonIgnore
@Override
protected Event getExecutionFailed() {
return getEvent(Event.EventType.EXECUTION_FAILED);
}
@JsonIgnore
@Override
protected Event getTimeoutEvent() {
return new RemoteEvent(this, getNodeUuid(), Event.EventType.TIMEOUT);
}
@JsonIgnore
@Override
protected Event getNotAllNodesAreAccessible() {
return new RemoteEvent(this, getNodeUuid(), Event.EventType.NOT_ALL_NODES_ARE_ACCESSIBLE);
}
@JsonIgnore
@Override
protected Event getNotAllObjectsAreAvailable() {
return new RemoteEvent(this, getNodeUuid(), Event.EventType.NOT_ALL_OBJECTS_ARE_AVAILABLE);
}
所以问题是实现此目标的最佳模式是什么?不建议采用这种方式。