Junior — Middle+
Early closure of connection before using Stream
livecode
Task condition
Conduct a review of the following code, paying attention to the order of resource closure.
public Stream<User> getUserStream() {
Connection connection = DataSourceObject.getConnection();
Stream<User> stream = executeAndReturnStream(connection);
connection.close();
return stream;
}
public void processUsers() {
Stream<User> users = getUserStream();
users.forEach(user -> System.out.println(user.getName()));
}