I wonder what happens to the next code execution.

Asked 2 years ago, Updated 2 years ago, 32 views

package jpastart.reserve.application;
import java.util.Optional;
import javax.persistence.EntityManager;
import jpastart.jpa.EMF;
import jpastart.reserve.model.User;

public class UserService {

    public UserService() {
        // // TODO Auto-generated constructor stub
    }

    public Optional<User> getUser(String email){
        EntityManager em = EMF.createEntityManager();
            try{
                    return Optional.ofNullable(em.find(User.class, email));
              }finally{
                    em.close();
            }


    }

}

Even if there is a code that returns in the middle of the above code, will the final part be executed?

java c++ c#

2022-09-22 10:54

1 Answers

Yes.

Even if the return statement is executed in the try block, the final block is executed.


2022-09-22 10:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.