In the below code, will the cahnges made to the Boolean value modifyPerson within the function be maintained or will it change to its initial value each time a new function is called.
Also i would like to know what difference is there if i use primitive boolean modifyPerson instead of Boolean .
public void validatePersonDTO(PersonDTO personDTO, TransactionLogDTO logDTO,ArrayList regionIdList,Boolean modifyPerson) {
try {
validateEffectiveIn(personDTO, logDTO,modifyPerson);
validateCdsId(personDTO, logDTO,regionIdList,modifyPerson);
validateEmpFirstName(personDTO, logDTO);
validateEmpLastName(personDTO, logDTO);
validateFinDept(personDTO, logDTO,modifyPerson);
validateEmployeeClass(personDTO, logDTO,modifyPerson);
validateWorkLoadandBudgetFTE(personDTO, logDTO,modifyPerson);
validateStatusandDescription(personDTO, logDTO,modifyPerson);
validateSalGrade(personDTO, logDTO);
validateCostRate(personDTO, logDTO);
validateJobCode(personDTO, logDTO,modifyPerson);
validateRateCardCharged(personDTO, logDTO);
validateSupervisorId(personDTO, logDTO);
}catch (Exception e) {
logDTO.setGyr("R");
logDTO.setMessage(logDTO.getMessage()+";"+"PersonDTO could not be validated");
//LOGGER.error("personDTO could not be validated: " + personDTO, e);
}
}
protected void validateEffectiveIn(PersonDTO personDTO, TransactionLogDTO logDTO,boolean modifyPerson) throws Exception{
todaysDate=convStringToDate(now(),Constants.DATE_PATTERN_LONG);
if(effIn.after(todaysDate)){
modifyPerson=true;
logDTO.setGyr("R");
logDTO.setMessage(logDTO.getMessage()+";"+"Error in Effective In date "+effIn.toString()+"cannot be greater than today’s date");
throw new Exception ("Error in Effective In date "+effIn.toString()+"cannot be greater than today’s date");
}
else{
modifyPerson=false;
}
}
Primitive variables are passed by value, so the changes to the
modifyPersonparameter will be lost as soon as the method exits.If you would like to preserve the change, return
booleanfrom your method, and assign it to themodifyPerson, like this:You can also create your own mutable class that encapsulates a
boolean, and lets its users get and set its value.