Erasure error, while using generic types in methods with similar signature
The problem is that both map(D dto)
and map(E entity)
, essentially have the same signature. being map(Object dto)
and map(Object entity)
. And there is no way for java to determine which method is being called when you call entityMapper.map(something);
So, you need to define your method as follows:
public abstract class EntityMapper{
public abstract <E extends AbstractEntity, D extends AbstractDto> E map(D dto);
public abstract <E extends AbstractEntity, D extends AbstractDto> D map(E entity);
}