I’m from a C# background where the iterators implement IDisposable interface. Are there any iterators in Java that implement a similar interface that makes them close automatically?
I’m from a C# background where the iterators implement IDisposable interface. Are there any
Share
Java’s Iterator is just an abstraction for iterating over some collection of objects. If the underlying data structure needs some clean-up after iteration (e.g. closing a file), then you need to keep a reference to that underlying object so you can do whatever must be done to “dispose” of it.