The line is:
recipeRepository.findAll().iterator().forEachRemaining(recipeSet::add);
recipeRepository
is my Spring data layer. It finds all the recipes in the DB and adds them to the set. I'm not really familiar with lambdas and ::
operators, so I'm wondering if there's another way to write argument recipeSet::add
down?
答案 0 :(得分:1)
问题是findAll()
方法返回一个迭代器。您可以通过在recipeRepository
中覆盖问题来解决问题,如下所示
@Query("SELECT r FROM Recipe r")
Set<Recipe> findAll();
这样它会返回一个集合然后你可以做类似的事情:
Set<Recipe> recipeSet = recipeRepository.findAll();
不做任何转换或迭代