I do not understand how the void method can conflict with the method that Iterator<T> returns.
The only way you can have such a conflict is when your lambda expression never ends normally, for example. ()->{ throw new RuntimeException(); } ()->{ throw new RuntimeException(); } or ()->{ for(;;); } ()->{ for(;;); } .
(or if your lambda expression consists of one method call that really returns Iterable )
For all other cases, you are right, there should not be such a conflict and, indeed, I could compile the equivalent code without any problems with jdk1.8.0_20 for regular lambda expressions (you did not include the code that causes the error in your question) .
If you are having a problem with a lambda expression that might end up fine and use the old jdk, you have encountered the error discussed here . This answer relates to the part of the language specification that defines the difference between void compatible and meaningful lambda expressions.
If you used another compiler or IDE, for example. Eclipse, make sure you are using the latest version and logging an error report if this error still occurs.
source share