I have the following enum:
enum FilterFactory {
INSTANCE;
private final Map<FilterType, Creator> creators;
private FilterFactory() {
creators = new HashMap<>();
class SimplCreator implements FilterCreator{
@Override
public FilterDTO createDto() {
return new FilterDTO();
}
} //Local class within the constructor
creators.put(FilterType.DATE, new FilterCreator(){
@Override
public FilterDTO createDto() {
return new DynamicDTO();
}
});
creators.put(FilterType.DROP_DOWN_LIST, new SimplCreator());
creators.put(FilterType.FIELD, new SimplCreator());
}
private static interface Creator{
public FilterDTO createDto();
}
//Other staff
}
The thing is I've never used the local classes within constructors bodies. Can it cause some bugs, is it bad to do so? Also, the constructor enu's constructor.