我有1个抽象类:ItemModel
,包含2个实现:ItemLogModel
和ItemLogModel
。 ItemModel
的构造函数受到保护,但仍可从ItemLogModel
访问。我希望受保护的构造函数只能由public abstract class Model<E> implements IModel {
private final Repository<? extends IModel, E> _repository;
protected E _entity;
protected Model(Repository<? extends IModel, E> repository, E entity)
this._repository = repository;
this._entity = entity;
}
...
}
public class ItemModel extends Model<Item> implements IItem {
...
@Override
public void setStatus(Status status, String logMessage) throws Exception {
super._entity.setStatus(status.toString());
super.update();
// CALLING protected constructor here!
new ItemLogModel(this, logMessage);
}
}
public class ItemLogModel extends Model<ItemLog> implements IItemLog {
protected ItemLogModel(ItemModel itemModel, String message) throws Exception {
super(REPOSITORY, new ItemLog());
super._entity.setAccessPointBean(itemModel.getEntity());
super._entity.setStatus(itemModel.getStatus().toString());
super._entity.setMessage(message);
super.save();
}
}
的子类访问。有人可以向我解释为什么这是可能的吗?
代码:
istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/