I have a HashMap
of different classes with different properties associated to each key. I am using Java 8's stream()
API to consolidate a list based on the property. My goal is to iterate the consolidated list, create an object based on the class, and use the interface to call the method for each one.
I am having trouble creating these objects once they have been consolidated. Here is my code:
private static final HashMap<Class<? extends DataAssessment>, Integer> TYPE_DATA_ASSESSMENT = new HashMap<Class<? extends DataAssessment>, Integer>() {{
put(AsertUsed.class, Definitions.DATA_TYPES.ELF);
put(ShellDeleted.class, Definitions.DATA_TYPES.ELF);
put(ShellUsed.class, Definitions.DATA_TYPES.ELF);
}};
Within my switch statement:
List<Class<?>> assessmentType = TYPE_DATA_ASSESSMENT.entrySet()
.stream()
.filter(item -> item.equals(Definitions.DATA_TYPES.ELF))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
for(int i = 0; i < assessmentType.size(); i++)
{
// This is where I am stuck
//
DataAssessment assessment = new (DataAssessment) assessmentType.get(i);
}