The drivers forEach method makes the use of lambda forEach ambiguous:
collection.find(filterBson).forEach(doc -> {
// do something here
});
results in the following compile error
"The method forEach(Block<? super Document>) is ambiguous for the type FindIterable<Document>"
Update
JAVA-3046 addresses the compiler error described above by deprecating MongoIterable#forEach(Block<T> block) so that it can be removed in the next major release. Once it's gone the compiler error will no longer occur. Under this ticket, we address the cursor leak that can occur when using Iterable#forEach(Consumer<T> consumer by overriding that method in every MongoIterable implementation to properly close the MongoCursor even when an exception occurs during the internal iteration of the method.
- related to
-
JAVA-3046 Deprecate MongoIterable#forEach
- Closed