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

Deprecate MongoIterable#forEach

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.9.0
    • Affects Version/s: None
    • Component/s: API
    • None

      The forEach(Block<? super TResult> block) method on MongoIterable conflicts with the default forEach method added to java.lang.Iterable in Java 8. If you try to use either with a lambda expression you get a compiler error which forces you to cast the lambda to either Block or Consumer, which is not intuitive.

      The default forEach method in Iterable, though, is dangerous to use with MongoIterable because it's not possible for it to force the MongoCursor to be closed in the case where Consumer.accept throws an exception, but in scope of JAVA-2010 we plan to address that. Given that, it makes sense to deprecate MongoIterable#forEach(Block<? super TResult> block) so that it can be removed in the next major release and users will stop getting the compiler error.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: