I have a specific code block and I would like to use it more efficiently, shortly using any feautures coming later than Java 8. I do not know if there exists any, so maybe I will continue doing it like before if you do not have any suggestion. This is the code block which I would like to modify:
if(page != null) {
coPage = companyService.findByCity(city, Integer.valueOf(page)-1);
}else {
page="1";
coPage = companyService.findByCity(city, 0);
}
I tried to do it using Optional but I have a problem with the variable "page" because I assign a value to local variable inside the lambda expression which compiler does not allow me to do so.