我想获得以下可运行的方法:
private List<Object[]> getDatabaseRecords(Product p, Set<LocalDate> months) {
return (List<Object[]>)MappingUtils.getSomethingByProduct(p)
.map(x -> dataAccess.findAll(new NativeDataQuery<>(createSqlForSomeStuff(new TreeSet<LocalDate>(months), x, p))))
.orElseGet(Collections::emptyList);
}
但是出现以下错误:
Error:(253, 19) java: incompatible types: java.util.List<java.lang.Object> cannot be converted to java.util.List<java.lang.Object[]>
运行的替代解决方案是:
private List<Object[]> getDatabaseRecords(Product p, Set<LocalDate> months) {
Optional<Class<? extends Base>> foo = MappingUtils.getSomethingByProduct(p);
return foo.isEmpty() ? Collections.emptyList() :
dataAccess.findAll(...);
}