gpt4 book ai didi

Java 枚举映射混淆

转载 作者:行者123 更新时间:2023-12-02 13:28:14 24 4
gpt4 key购买 nike

嗨,谁能帮我理解下面这行代码?

      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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com