我收到警告“参数化类 'MapperService' 的原始使用和“未经检查地调用 'mapSourceToBehandlerKrav(T)' 作为原始类型的成员......来自 IntelliJ。我并没有真正掌握泛型的概念,试图弄清楚。但是对这些警告的一些解释和解决方案可能会有所帮助
界面:
public interface MapperService<T> {
Behandlerkrav mapSourceToBehandlerkrav(T sourceInput) throws DataSourceException, MapperException;
}
实现类:
public class XMLToDomainMapper implements MapperService {
public Behandlerkrav mapSourceToBehandlerkrav(Object input) throws DataSourceException, MapperException {
if (!(input instanceof File)) {
throw new DataSourceException(
"Input er av ugyldig type: " + input.getClass() + " | tillat type = " + "File");
}
// More stuff
}
调用实现类(出现警告的地方):
public class InnrapporteringServiceImpl implements InnrapporteringService {
MapperService kildesystemInputMapper; <-- IntelliJ WARNING HERE
public InnrapporteringServiceImpl(XMLToDomainMapper mapper) {
this.kildesystemInputMapper = mapper;
}
@ServiceActivator(inputChannel = "sftChannel")
public void init(Message<File> message) {
// call mapper service
// call persistence service
// call reporting service
var timestamp = message.getHeaders().getTimestamp();
Behandlerkrav behandlerkrav = kildesystemInputMapper.mapSourceToBehandlerkrav(message.getPayload()); <-- IntelliJ WARNING here
}
}