Deprecated Iterators

I've seen that all of the Iterator<T> extension functions have been deprected, with a comment to use Stream<T> instead. The problem I'm having is that I have a bunch of Java code where I have to use iterators (I'm not simply getting an iterator from a collection), and as a result, all of the calls are marked as deprecated. What should I be using instead in this case? What's the reason for the deprecation?

Using iterators other than for iteration has been proven to be error-prone. It is a mutable object, and if you try to use it like a lazy collection it will inevitably break things if you are not really careful. That's why we dropped extension functions on iterators and introduced Stream<T> type for lazy and functional sequence processing. Basically, operations on Iterable<T> are eager and return snapshots, and operations on Stream<T> are lazy and return streams composed out of original stream and transformations.

Can you elaborate more on how you are using iterators and share some examples of your code? Is it performance-critical code? Are you bound by an external interface you need to comply with?

I'm on a project that uses Apache Sling, and starting to use Kotlin with it. Unfortunately, they have lots of APIs like:

 
    Iterator<Resource> listChildren();

Which is the only way to access certain resources. Now, it's not so hard to switch to use the iterator 'in' syntax, but was definitely enjoying kotlin's excelent APIs. I suppose I could develop some extension fucntions to allow for using more of the kotlin API set.

I'm looking here: http://sling.apache.org/apidocs/sling7/index.html And there are two members: getChildren() that returns Iterable, and listChildren() returning Iterator. I'm unsure why they made this decision, but at least you can use the iterable APIs.

wrong thread :/

Looks like you were going to reply to the Dagger topic?

yes, sorry... Don't know what happened (login interfered...)