Généricité : erreur de compilation (avec Maven)
Bonjour,
J'écris un DAO générique avec Spring/Hibernate, mais j'ai un problème de compilation :
Interface :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
/**
* Read an entity
* @param <Entity> Entity class
* @param entityClass Entity class
* @param id Entity ID
* @return Entity
* @throws DataAccessException Data access error
* @throws IllegalArgumentException Null entityClass or null id
*/
public <Entity extends AbstractEntity> Entity read(Class<Entity> entityClass, Serializable id)
throws DataAccessException, IllegalArgumentException; |
Implémentation :
Code:
1 2 3 4 5 6 7
| @Transactional(readOnly = true)
@Override
public <Entity extends AbstractEntity> Entity read(Class<Entity> entityClass, Serializable id) {
ArgumentTools.checkNotNull(entityClass);
ArgumentTools.checkNotNull(id);
return GenericsTools.cast(getHibernateTemplate().get(entityClass, id)); // ERROR
} |
Méthode utilitaire :
Code:
1 2 3 4 5 6 7 8 9 10 11
| /**
* Object cast
* @param <I> Input type
* @param <O> Output type
* @param i Input object
* @return Output object
*/
@SuppressWarnings("unchecked")
public static <I, O extends I> O cast(I i) {
return (O) i;
} |
Ca compile avec Eclipse, mais seulement parfois avec Maven :
Citation:
type parameters of <O>O cannot be determined; no unique maximal instance exists for type variable O with upper bounds Entity,java.lang.Object
Une idée de la correction à apporter ?
Merci.