list.stream().collect(Collectors.toList()); returns 空列表
list.stream().collect(Collectors.toList()); returns empty list
choices 是一个包含两个元素的列表
但是 choices.stream().collect(Collectors.toList());
returns 一个空列表
有人知道为什么吗?
//returns poll with list of choices
public Poll accessPoll(String pollId) {
return pollRepository.findById(pollId).orElseThrow(
() -> new IllegalStateException(String.format("No poll found for the ID: %s.", upperCasePollId)));
}
List<Choice> choices = pollManager.accessPoll(pollId).getChoices(); //returns list of choices
List<Choice> choices1 = pollManager.accessPoll(pollId).getChoices()
.stream().collect(Collectors.toList()); //returns empty list
仔细看你的截图。您的方法 getChoices()
returns 不是常规列表,而是 EclipseLink 中的 IndirectList which extends not a regular Collection
but a Vector
and that is why streams don't work as expected. This is a known bug,
你可以阅读更多 here and .
要克服此问题,您可以尝试将 EclipseLink 版本更新到 2.6.0,或者您可以尝试用一个新的集合来包装它,例如 new ArrayList<>()
choices 是一个包含两个元素的列表
但是 choices.stream().collect(Collectors.toList());
returns 一个空列表
有人知道为什么吗?
//returns poll with list of choices
public Poll accessPoll(String pollId) {
return pollRepository.findById(pollId).orElseThrow(
() -> new IllegalStateException(String.format("No poll found for the ID: %s.", upperCasePollId)));
}
List<Choice> choices = pollManager.accessPoll(pollId).getChoices(); //returns list of choices
List<Choice> choices1 = pollManager.accessPoll(pollId).getChoices()
.stream().collect(Collectors.toList()); //returns empty list
仔细看你的截图。您的方法 getChoices()
returns 不是常规列表,而是 EclipseLink 中的 IndirectList which extends not a regular Collection
but a Vector
and that is why streams don't work as expected. This is a known bug,
你可以阅读更多 here and
要克服此问题,您可以尝试将 EclipseLink 版本更新到 2.6.0,或者您可以尝试用一个新的集合来包装它,例如 new ArrayList<>()