我想创建一个Map<Long, Enum< ? extends SomeInterface>
。对我来说哪个是最好的选择?混乱的数据结构
我想这一个
private Map<Long, Enum<? extends SomeInterface>[]> questionIdToanswersMapping = Collections.unmodifiableMap(Stream.of(
new SimpleEntry<>(QuestionEnum1.getQuestionId(), AnswerEnum1.values()),
new SimpleEntry<>(QuestionEnum2.getQuestionId(), AnswerEnum2.values()),
new SimpleEntry<>(QuestionEnum3.getQuestionId(), AnswerEnum3.values()),
new SimpleEntry<>(QuestionEnum4.getQuestionId(), AnswerEnum4.values()),
new SimpleEntry<>(QuestionEnum5.getQuestionId(), AnswerEnum5.values()))
.collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())));
但它给错误“无法转换从Map<Object,Object>
到Map<Long,Enum<? extends SomeEnum>[]>
”。我是新来的。请帮忙!
我需要将不可修改的问题ID映射到相应的可能答案值。可能的答案是枚举
可能的答案被包裹这样的:
public class RecognizedAnswers {
public enum AnswerEnum1 implements SomeInterface;
public enum Answer2 implements SomeInterface;
}
因此对于每个QuestionId,都有相同的AnswerEnum集合,它们有什么不同? – Beri
他们是不同的。每个AnswerEnum扩展SomeEnum – user3681970
但它不总结。在你的例子中,你有一组答案,根据描述,你需要将Single QuestioId映射到单个答案 – Beri