Reputation: 907
I have a list A. And from that list, i want to create a new list B by using one field of list A for construction of objects in list B. However i am unable to get the syntax right. Currently i have
List<B> listB = listA.stream().map(id -> {
ObjectB b = Mockito.mock(ObjectB.class);
when(b.getId()).thenReturn(id.toString());
when(b.getNumericId()).thenReturn(id);
}).collect(Collectors.toList());
However i am getting syntax error on map which i am unable to understand.
Upvotes: 3
Views: 69
Reputation: 120978
If you have used {}
for the lambda creation, you are supposed to use return
also, thus:
List<B> listB = listA.stream().map(id -> {
ObjectB b = Mockito.mock(ObjectB.class);
when(b.getId()).thenReturn(id.toString());
when(b.getNumericId()).thenReturn(id);
return b;
})
Upvotes: 4