嗨,谁能帮我理解下面这行代码?
private Map<EnumType, Pair<Long, Long>> processToProductLineAndIndustryMap = new EnumMap<EnumType, Pair<Long, Long>>(
Collections.unmodifiableMap(Stream.of(
new SimpleEntry<>(EnumType.SOME_TYPE,
Pair.of(Question.getProductLineQuestionId(), Question.getAdvertiserIndustryQuestionId())))
.collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))));
我对此很陌生。网上查了几篇文章,但无法弄清楚。
我想创建一个不可修改的 map<EnumType, Pair<Long, Long>>
。基于枚举类型,我想获取一对 Long 并查看它是否包含特定的 long 。请帮助我找出适合我的用例的最佳数据结构
最佳答案
您可以使用Collections.singletonMap(key, value)
。
private Map<EnumType, Pair<Long, Long>> processToProductLineAndIndustryMap = new EnumMap<EnumType, Pair<Long, Long>>(
Collections.singletonMap(EnumType.SOME_TYPE, Pair.of(Question.getProductLineQuestionId(), Question.getAdvertiserIndustryQuestionId())));
关于Java 枚举映射混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43303618/