I have a Constants variable defined as final as seen below:
Constants.javapublic static final List<Integer> SPECIAL_CASE = Arrays.asList (2, 3, 6, 7);
Its an Integer list of values. I have a service layer with following code:
ReportServiceImpl.javapublic class ReportServiceImpl{/////////Report repObj = new Report();BeanUtils.copyProperties(repPending, repObj);..........//////if(Constants.SPECIAL_CASE.stream().anyMatch(element ->repObj.getSpecialCase() == element)) {System.out.println("It is a Special report...");}if((Constants.SPECIAL_CASE.stream().anyMatch(element -> repObj.getSpecialCase() == element)) || ((repObj.getMp() == null || repObj.getMp() == 0)&& (repObj.getMPro() == null || repObj.getMPro() == 0))){// do something........//}/////////}
If you look at how the object is formed its coming from another object and BeanUtils copies from one object to another. Im using the new object for if condition.The 1st if checks if the repObj.getSpecialCase() macths with Integer list and it works fine. No issues the sysout gets printed. Next I am adding the same condition in the 2nd if loop inaddition to other conditions and im getting a red on the code with "Variable used in lambda expression should be final or effectively final"
Im not sure why the 1st if works and repObj on the 2nd if shows this error. The class doesnt compile. Any input on why this happens and how to handle this exception. Thank you so much.