Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2010

Support the use of Java 8 lambdas and MongoIterable.forEach()

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.9.0
    • Affects Version/s: None
    • Component/s: API
    • None

      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.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            andre.defrere@mongodb.com Andre de Frere
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: