如何将此代码转换为使用流的代码?一行,如果可能的话:
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
不是很好,因为它们是有代价的,但是您可以这样做: