I\'m using a Java-API which heavily uses the Autoclosable-Interface and thus in Java try-with-resources. However in Java you can specify
There is no standard solution for this. If you had all of the Closable
instances ready at the start, you could use your own self-defined methods to handle them, like this blog post or this repository shows (and here is the discussion on the official forums that led to the latter).
In your case however, where subsequent objects rely on the previous ones, none of these apply like a regular try-with-resources
would.
The only thing I can suggest is trying to define helper functions for yourself that hide the nested use
calls, and immediately place you in the second/third/nth layer of these resourcs acquisitions, if that's at all possible.