我有以下结构:
public abstract class BaseVersionedEntity {
private long id;
private List<BaseRevision<? extends BaseVersionedEntity>> versions;
public BaseRevision<? extends BaseVersionedEntity> getLatestRevision() {
return versions.get(versions.size() - 1);
}
public abstract BaseRevision<? extends BaseVersionedEntity> newRevision();
}
public abstract class BaseVersionedEntityData<E> {
private long id;
private BaseRevision<E> revision;
}
public abstract class BaseRevision<E> implements Comparable<BaseRevision<E>> {
private long id;
private Timestamp timestamp;
private E versionedEntity;
private BaseVersionedEntityData<E> versionedEntityData;
public BaseVersionedEntityData<E> getVersionedEntityData() {
return versionedEntityData;
}
}
这将通过以下方式实现:
public class PersonEntity extends BaseVersionedEntity {
@Override
public BaseRevision<? extends BaseVersionedEntity> newRevision() {
PersonRevision newRevision = new PersonRevision();
newRevision.setTimestamp(new Timestamp(System.currentTimeMillis()));
getRevisions().add(newRevision);
return newRevision;
}
}
public class PersonData extends BaseVersionedEntityData<PersonEntity> {
}
public class PersonRevision extends BaseRevision<PersonEntity> {
}
在我的代码中的某处,我将执行以下调用:
// is not null
PersonEntity personEntity;
PersonData personData = personEntity.getLatestRevision().getVersionedEntityData();
由于某些原因标记为类型不匹配...
Type mismatch: cannot convert from BaseVersionedEntityData<capture#1-of ? extends BaseVersionedEntity> to PersonData
谁能找到错误??或者有什么提示??
谢谢!!本杰明