流映射多个类型

  • 本文关键字:类型 映射 java guava
  • 更新时间 :
  • 英文 :


如何将此代码转换为使用流的代码?一行,如果可能的话:

List<Key<String, ?>> keys = Lists.newArrayList();
for (Map.Entry<String, House> entry : Houses.all().entrySet()) {
keys.add(new Key<>(entry.getKey(), 
HousesTypes.getFor(entry.getValue()));
}
return ImmutableList.of(houseConstructor.newInstance(5, keys));

好吧,我的意思是"一行";使用Stream不是很好,因为它们是有代价的,但是您可以这样做:

<>之前返回ImmutableList.of (houseConstructor.newInstance (5,Houses.all ().entrySet ().stream (). map(条目→new Key<>(entry.getKey(), housestyles . getfor (entry.getValue())).collect (Collectors.toList ())(div);

最新更新