Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace this lambda with a method reference. (sonar.java.source not set. Assuming 8 or greater.)

Tags:

java

sonarqube

List<UUID> insrVrfyIds = insrVrfyObjsNew.stream().map(insrVrfy -> insrVrfy.getCustomerInsrVrfyId()).collect(Collectors.toList());

For the following code i am getting a warning as i mentioned in title. Can anyone please explain me how to convert this.

here in the above code, i have a list of objects from that i want to extract all the primary keys using lambda expression.But i am getting the violation like "Replace this lambda with a method reference. (sonar.java.source not set. Assuming 8 or greater.)"

like image 661
raji Avatar asked Sep 13 '17 14:09

raji


2 Answers

Well it probably means that you could write it also like this:

List<UUID> insrVrfyIds = insrVrfyObjsNew.stream().map(InsrVrfy::getCustomerInsrVrfyId).collect(Collectors.toList());

I assumed there that your instance insrVrfy is of a class InsrVrfy so if I was mistaken please correct me.

Here you could read more about method reference.

like image 93
pokemzok Avatar answered Oct 24 '22 04:10

pokemzok


List<UUID> insrVrfyIds =
                    insrVrfyObjsNew.stream().map(CustomerInsrVrfy::getCustomerInsrVrfyId).collect(Collectors.toList());

This worked for the above.. That's my bad, it's working by replacing the variable (insrVrfy) with it's class name(CustomerInsrVrfy).

like image 24
raji Avatar answered Oct 24 '22 03:10

raji