嗨试图找出如何映射到EnumMap没有成功.目前我正在分2步完成,我创建了地图,然后我将其设为EnumMap.问题是.
从效率的角度来看,最好从输入中获取值,使它们成为集合然后流式传输,或者仅使用toMap,因为它现在是正确的.谢谢
Map<CarModel, CarBrand> input...
final Map<CarBrand, CarsSellers> ret = input.values()
.stream().filter(brand -> !brand.equals(CarBrand.BMW))
.collect(toMap(Function.identity(), brand -> new CarsSellers(immutableCars, this.carsDb.export(brand))));
final EnumMap<CarBrand, CarsSellers> enumMap = new EnumMap<>(CarBrand.class);
enumMap.putAll(ret);
Run Code Online (Sandbox Code Playgroud)