Cannot be applied to '(<method reference>)'

58 Views Asked by At
@Component
public class AccountDtoConverter {
    private final CustomerDtoConverter customerDtoConverter;
    private final TransactionDtoConverter transactionDtoConverter;

    public AccountDtoConverter(CustomerDtoConverter customerDtoConverter, TransactionDtoConverter transactionDtoConverter) {
        this.customerDtoConverter = customerDtoConverter;
        this.transactionDtoConverter = transactionDtoConverter;
    }

    public AccountDto convert(Account from) {
        return new AccountDto(from.getId(),
                from.getBalance(),
                from.getCreationDate(),
                customerDtoConverter.convertToAccountCustomer(from.getCustomer()),
                Objects.requireNonNull(from.getTransaction())
                        .stream()
                        .map(transactionDtoConverter::convert)
                        .collect(Collectors.toSet()));
    }
}

@Component
public class TransactionDtoConverter {

    public TransactionDto convert(Transaction from) {
        return new TransactionDto(from.getId(),
                from.getTransactionType(),
                from.getAmount(),
                from.getTransactionDate());
    }
}

data class AccountDto( 
    val id: String?,
    val balance: BigDecimal? = BigDecimal.ZERO,
    val creationDate: LocalDateTime,
    val customer: AccountCustomerDto?,
    val transactions: Set<TransactionDto>? ) 

I've took error 'map(java.util.function.Function<? super org.hibernate.Transaction,? extends R>)' in 'java.util.stream.Stream' cannot be applied to '()' in;

.map(transactionDtoConverter::convert)

that line. I shared the whole code block upside. I'm using Intellij IDEA. And that is just one of my classes.

My java version is JDK 19.0.2, I've created that class while watching one course on YouTube. But instructor was using the 11.0 version. Could that error be caused java version ? Lastly, we did example that regarding spring boot.

0

There are 0 best solutions below