0

I have a connection-object which implements java.io.Closeable and I make use of try-with-resource:

version 1:

public List<User> findUsers(Query query) {
    try (this.connection) {
        return conn.find(query);
    }
    // no catch block defined
}

All works, however I am wondering what is the difference in terms of behaviour (for example, exceptions,..) between version 1 and 2:

version 2:

public List<User> findUsers(Query query) {
     var users = this.connection.find(query);
     this.connection.close();
     return users;
}
nimo23
  • 5,170
  • 10
  • 46
  • 75

0 Answers0