0

I want to create an abstract class to be able to convert entities into dto and dto into entities with the modelmapper library. What am I doing wrong?

public abstract class AbstractConverter<Entity,DTO> {

    @Autowired
    ModelMapper modelMapper;

    public Entity toEntity(DTO dto) {
        return modelMapper.map(dto, Entity.class);
    }

}

This is the error

Illegal class literal for the type parameter Entity
Luca De Salve
  • 11
  • 1
  • 2

1 Answers1

1

The method signature must be

public <Entity, DTO> Entity toEntity(DTO dto) {
    return modelMapper.map(dto, Entity.class);
}
Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82