我有这个实体关系模型:
// Entity interface
public interface Entity<Reference extends Entity<Reference>> extends Iterable<Attribute<Reference, ?>> {
// set a referrer and the RelationMetadata to this Entity
<Referrer extends Entity<Referrer>> void setReferrer(RelationMetadata<Referrer, Reference> relationMetadata, Referrer referrer);
some other methods...
}
// Relation Metadata is a relation descriptor
public class RelationMetadata<Referrer extends Entity<Referrer>, Reference extends Entity<Reference>> {
some methods...
}
我想创建我的实体('selectedEntity')来读取它的元数据,加载它的引用者并将它们连接到'selectedEntity'。所以我的用法是:
// obtain the entity metadata
EntityMetadata<E> entityMetadata = EntityManager.getEntityMetadata(selectedEntity.getClass());
// cycle on each relation my entity is reference
for (Iterator<RelationMetadata<? extends Entity<?>, E>> iterator = entityMetadata.getAsReferencesRelationsMetadataIterator(); iterator.hasNext();) {
// for each relation
RelationMetadata<? extends Entity<?>, E> relationMetadata = (RelationMetadata<? extends Entity<?>, E>) iterator.next();
// instance dao
Dao<?> referrerDao = DaoManager.getDao(relationMetadata.getReferrer());
some code..
// select referrer entity
Entity<?> referrer = referrerDao.selectByKey(...);
// set referrer to my 'selectedEntity'
selectedEntity.setReferrer(relationMetadata, referrer);
}
问题是我得到这个编译错误调用方法'setReferrer':
'The method setReferrer(RelationMetadata<Referrer,E>, Referrer) in the type Entity<E> is not applicable for the arguments (RelationMetadata<capture#16-of ? extends Entity<?>,E>, Entity<capture#18-of ?>)'
我知道我加载的 'referrer' 已正确连接到 'relationMetadata' 但我如何才能提示编译器呢?
这是一个非常烦人的问题,我不知道如何解决。
谢谢G。