How to fix error below?
Bad return type in method reference: cannot convert RecipeIndicatorsDto to R
thanks guys
public List<RecipeIndicatorsDto> listByUploadTime(LocalDateTime localDateTime) {
if(localDateTime!=null) {
QRecipeIndicator qRecipeIndicator = recipeIndicatorRepo.getQEntity();
QOrder qOrder=orderRepo.getQEntity();
List<Predicate> predicates = new ArrayList<>();
predicates.add(qRecipeIndicator.uploadTime.before(localDateTime));
List<RecipeIndicator> recipeIndicators = recipeIndicatorRepo.find(predicates, new PageRequest(0, 100));
List<Order> orders=orderRepo.find(null,new PageRequest(0,100));
return recipeIndicators.stream()
.map(DtoFactory::recipeIndicatorsDto)
.collect(Collectors.toList());
}
public static RecipeIndicatorsDto recipeIndicatorsDto(RecipeIndicator recipeIndicator, Order order) {
if (recipeIndicator != null&&order!=null) {
RecipeIndicatorsDto recipeIndicatorsDto = new RecipeIndicatorsDto();
recipeIndicatorsDto.setVerificationStatus(recipeIndicator.getVerificationStatus());
recipeIndicatorsDto.setUploadTime(recipeIndicator.getUploadTime());
recipeIndicatorsDto.setRemark(order.getRemark());
recipeIndicatorsDto.setUseDays(order.getUseDays());
}
DtoFactory::recipeIndicatorsDto
is a method reference to a static method that requires an RecipeIndicator
parameter and an Order
parameter.
Since you are passing it to map
of a Stream<RecipeIndicator>
, only the RecipeIndicator
instance is available.
You can use a lambda expression instead:
.map(recipeIndicator -> DtoFactory.recipeIndicatorsDto(recipeIndicator, qOrder))
I'm not sure which Order
instance you want to pass to it. I guessed it might be qOrder
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With