Sonar tells me "Replace this lambda with a method reference"
public class MyClass {
private List<SomeValue> createSomeValues(List<Anything> anyList) {
return anyList //
.stream() //
.map(anything -> createSomeValue(anything)) //
.collect(Collectors.toList());
}
private SomeValue createSomeValue(Anything anything) {
StatusId statusId = statusId.fromId(anything.getStatus().getStatusId());
return new SomeValue(anything.getExternId(), statusId);
}
}
Is this possible here? I tried several things, like
.map(MyClass::createSomeValue) //
but I need to change the method to static then. And I am not a big fan of static methods.
Explanation of SonarQube is:
Method/constructor references are more compact and readable than using lambdas, and are therefore preferred.