I want to create a Map<Long, Enum< ? extends SomeInterface>
. Which is the best option for me?
I tried this one
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())));
But it is giving error "cannot convert from Map<Object,Object>
to Map<Long,Enum<? extends SomeEnum>[]>
". I am new to this. Please help!
I need unmodifiable map of question Id to the corrosponding possible answers values. Possible answers are Enums
Possible Answers are wrapped like this :
public class RecognizedAnswers {
public enum AnswerEnum1 implements SomeInterface;
public enum Answer2 implements SomeInterface;
}