1/ Working code:
public Student process (int id, name){
Optional studentOpt = myrepo.findById(id);
studentOpt.isPresent() {
return upd
Given that your methods updateStudent
and createStudent
involve some form of side effect and you should generally prefer side effect free lambdas, I don't recommend you use them here. In fact, a simple if-then-else block would be sufficient. However, if you are curious, the equivalent lambda would look like:
return studentOpt
.map(unused -> updateStudent(id, name))
.orElseGet(() -> createStudent(id, name));