vendredi 3 juin 2016

How can I solve this warning when i use maven to compile ParameterizedType

During this time,I use generics to handle some mapping.Code like this:

@Component
public class AbstractEntityMapping<entity, dto> implements EntityMapping<entity, dto> {
@Autowired
protected Mapper mapper;

private Logger logger = LoggerFactory.getLogger(AbstractEntityMapping.class);


@SuppressWarnings("unchecked")
public dto entityToDTO(entity entity) {
    if (entity == null) {
        return null;
    }
    try {
        final dto dto = (dto) getDTOClass().newInstance();
        mapper.map(entity, dto);
        return dto;
    } catch (Exception e) {
        logger.error("mapping entity to dto error", e);
    }
    return null;
}

private Class getEntityClass() {
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    Type type = genericSuperclass.getActualTypeArguments()[0];
    Class<entity> clazz;
    if (type instanceof ParameterizedTypeImpl) {
        clazz = (Class<entity>) ((ParameterizedTypeImpl) type).getRawType();
    } else {
        clazz = (Class<entity>) type;
    }
    return clazz;
}

private Class getDTOClass() {
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    Type type = genericSuperclass.getActualTypeArguments()[1];
    Class<entity> clazz;
    if (type instanceof ParameterizedTypeImpl) {
        clazz = (Class<entity>) ((ParameterizedTypeImpl) type).getRawType();
    } else {
        clazz = (Class<entity>) type;
    }
    return clazz;
}

}

When I use maven to compile this code,it hint me that:

[WARNING] AbstractEntityMapping.java:[131,39]     sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl是内部专用 API, 可能会在未来发行版中删除

How can I solve this warning?Does any class can replace ParameterizedTypeImpl?





Aucun commentaire:

Enregistrer un commentaire