I have an enum
with another enum
as a parameter
public enum MyEntity{
Entity1(EntityType.type1,
....
MyEntity(EntityType type){
this.entityType = entityType;
}
}
I want to create a method that return the enum
by type
public MyEntity getEntityTypeInfo(EntityType entityType) {
return lookup.get(entityType);
}
usually I would have written
private static final Map<EntityType, EntityTypeInfo> lookup = new HashMap<>();
static {
for (MyEntity d : MyEntity.values()){
lookup.put(d.getEntityType(), d);
}
}
What is the best practice to write it with java stream?