我有以下抽象类:
public abstract class AbstractRepository<O, PK extends Serializable>{
protected EventDispatcher eventDispatcher;
protected GenericDao<O,PK> dao;
protected ApplicationPublisher publisher;
protected State state;
protected InternalPublisher internalPublisher;
@PostConstruct
private void initialise(){
eventDispatcher.addHandler(this);
}
protected <T extends GenericDao<O,PK>> AbstractRepository(T dao, State state, ApplicationPublisher publisher, InternalPublisher internalPublisher, EventDispatcher eventDispatcher){
this.dao = dao;
this.state = state;
this.publisher = publisher;
this.internalPublisher = internalPublisher;
this.eventDispatcher = eventDispatcher;
}
@HandleEvent
private void handleDataContributorCreatedEvent(DataContributorDeletedEvent event){
List<O> stats = new ArrayList<O>();
for(int x = -1 ; x < 50 ; x++){
for (int y = 0 ; y < 360 ; y = y + 5){
stats.add(**Need to instantiate paramater type O here**);
}
}
dao.save(stats);
}
}
在事件处理程序方法中 - 我希望能够创建参数类型 O 的实例 - 但不确定如何做到这一点。任何有关最佳方法的帮助将不胜感激。