I assume that there are typos in your code (the method should be static, in my opinion, your constructor is doing no-op at the moment), but if I follow you, you can create a stream from an array of enumerations and use the toMap collector. matching each enum with its EntityType for keys and matching the instance itself as a value:
private static final Map<EntityType, EntityTypeInfo> lookup = Arrays.stream(EntityTypeInfo.values()) .collect(Collectors.toMap(EntityTypeInfo::getEntityType, e -> e));
The toMap makes no warranties regarding the returned implementation of the map (although this is currently a HashMap ), but you can always use the overloaded version if you need more control, providing merge dumping as a parameter.
You can also use one more trick with a static class and fill the map in the constructor.
source share