我想创建一个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;
}