Reputation: 123
I am trying to iterate through a bson document in java but I get an error
new Document().append("test",1).forEach(record -> {
System.out.println(record); ^ error here
});
I get:
Error:(556, 49) java: incompatible types: incompatible parameter types in lambda expression, expected parameter 2 but found 1
when I try to add another parameter everything broke
new Document().append("test",1).forEach(record, param2 -> {
Upvotes: 5
Views: 3679
Reputation: 56423
Due to the fact that Document
implements the Map
interface, that means it also inherits the default forEach
method which takes a BiConsumer
as a parameter. Thus your lambda should be like this:
.forEach((key, value) -> { ... }
Upvotes: 3