title: Java MongoDB - specify which forEach to use
body: <p>I am using Java 8 and MongoDriver 3.5 for a Java project</p>
  
  <p>I retrieve a <code>FindIterable&lt;Document&gt;</code> with the method <code>collection.find()</code>, and I would like to use a <strong>forEach</strong> on this Iterable, but I have a problem with my forEach</p>
  
  <p>Here is my code so far</p>
  
  <pre><code>MongoDatabase database = this.mongoClient.getDatabase(url);
  MongoCollection&lt;Document&gt; collection = database.getCollection("myCollection");
  
  FindIterable&lt;Document&gt; documentList = collection.find();
  
  documentList.forEach((Document document) -&gt; {
      System.out.println(document.toJson());
  });
  </code></pre>
  
  <p>Spring Tools Suite doesn't give me an error, however when I compile my code, I got the following error</p>
  
  <pre><code>error: reference to forEach is ambiguous
  documentList.forEach((Document document) -&gt; System.out.println(document.toJson()));
                      ^
  both method forEach(Consumer&lt;? super T&gt;) in Iterable and method forEach(Block&lt;? super TResult&gt;) in MongoIterable match
    where T,TResult are type-variables:
      T extends Object declared in interface Iterable
      TResult extends Object declared in interface MongoIterable
  </code></pre>
  
  <p>So, I was wondering, is there a way to tell Java to use the native forEach method instead of the mongo one ? 
  For example in php you can do something like /<em>@var $foo String</em>/ to help compiler</p>
  
  <p>PS : I know I could use a for(Document document : documentList) but we still have a problem with the cursor not being closed on error. (as seen on <a href="https://stackoverflow.com/a/30469815/5578655">this answer</a> ) but if my question is really unsolvable, I can use this fallback</p>