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.
- is related to
-
JAVA-2010 Support the use of Java 8 lambdas and MongoIterable.forEach()
- Closed