Home > database >  Operator ' ' cannot be applied to 'java.lang.String', 'void'
Operator ' ' cannot be applied to 'java.lang.String', 'void'

Time:06-20

I'm stuck in this error that shows up " Operator ' ' cannot be applied to 'java.lang.String', 'void' " after I tried to fetch data from a list of an object with the help of foreach I don't understand what's the problem, this is where the problem show up

public void sendMailOwner(VacacionRequest PaidRequest) {
        CollaboratorDTO validator = OrganizationalUintService.findValidator(collaboratorTransformer.entityTranferToDTO(PaidRequest.getCollaborator()));
        EmailService.sendSimpleMessage(PaidRequest.getCollaborator().getEmail(),
                "EverHoliday",
                " Bonjour " PaidRequest.getCollaborator().getFirstname() " " PaidRequest.getCollaborator().getLastname() ","
                  "\n Votre demande de Congé payé du date " PaidRequest.getDatesRequest().forEach((p)->p.getStartDate) "au" PaidRequest.getDatesRequest().forEach((p)->p.getEndDate) " est en attente de validation par : "
                         validator.getLastname() " " validator.getFirstname()
                  " \n Cordialement.");
    }

PaidRequest.getDatesRequest().forEach((p)->p.getStartDate) as you can see i want to fetch all startdate from datesrequest list

this is DatesRequest Model

package com.example.demo.model;

import java.time.LocalDate;

import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
@Node
public class DatesRequest {
    @Id @GeneratedValue
    private Long id;    
 private LocalDate startDate;
 private LocalDate endDate;
 private double duration;
public DatesRequest(LocalDate startDate, LocalDate endDate, double duration) {
    this.startDate = startDate;
    this.endDate = endDate;
    this.duration = duration;
}
public DatesRequest() {
}
public LocalDate getStartDate() {
    return startDate;
}
public void setStartDate(LocalDate startDate) {
    this.startDate = startDate;
}
public LocalDate getEndDate() {
    return endDate;
}
public void setEndDate(LocalDate endDate) {
    this.endDate = endDate;
}
public double getDuration() {
    return duration;
}
public void setDuration(double duration) {
    this.duration = duration;
}
public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}

}

and this is where we declared DatesRequest in PaidRequest Model

public PaidRequest(LocalDate requestDate, String statut, String typeOfTime, List<DatesRequest> datesRequest,
        Collaborator collaborator, String description, double balanceUsed,String justification) {
    super(requestDate, statut, typeOfTime, datesRequest, collaborator);
    this.description = description;
    this.balanceUsed = balanceUsed;
    this.justification = justification;
}

CodePudding user response:

As long you concatenate strings the both arguments of ' ' operator must be strings. But PaidRequest.getDatesRequest().forEach((p)->p.getStartDate) this is not a string but void, if you want to get it as comma separeted string use something like:

String.join(",", PaidRequest.getDatesRequest().map((p)->p.getStartDate)) (remember to collect to list)

CodePudding user response:

This is happening because you are trying to join String with void datatype.

PaidRequest.getDatesRequest().forEach is returning void datatype.

If you want to join getStartDate to your string, then I would recommend extract it to Array or list & then join it later.

  • Related