public static Set<NurseViewPrescriptionWrapper> create(final Set<NurseViewPrescriptionDTO> nurseViewPrescriptionDTOs) {
return nurseViewPrescriptionDTOs.stream()
.map(new Function<NurseViewPrescriptionDTO, NurseViewPrescriptionWrapper>() {
@Override
public NurseViewPrescriptionWrapper apply(NurseViewPrescriptionDTO input) {
return new NurseViewPrescriptionWrapper(input);
}
})
.collect(Collectors.toSet());
}
I convert above code to java 8 lamda function as below.
public static Set<NurseViewPrescriptionWrapper> create(final Set<NurseViewPrescriptionDTO> nurseViewPrescriptionDTOs) {
return nurseViewPrescriptionDTOs.stream()
.map(input -> new NurseViewPrescriptionWrapper(input))
.collect(Collectors.toSet());
}
Now, I am receiving sonar issue, like Lambdas should be replaced with method references
, to '->' this symbol. How i can fix this issue ?
Your lambda,
.map(input -> new NurseViewPrescriptionWrapper(input))
can be replaced by
.map(NurseViewPrescriptionWrapper::new)
That syntax is a method reference syntax. In the case of NurseViewPrescriptionWrapper::new
is a special method reference that refers to a constructor
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