public enum Dictionaries {
FIRST_DICTIONARY(FirstDictionary.class),
SECOND_DICTIONARY(SecondDictionary.class);
private Class<? extends DictionaryModel> clazz;
private Dictionary(Class<? extends DictionaryModel> clazz) {
this.clazz = clazz;
}
public Class<? extends DictionaryModel> clazz() {
return this.clazz;
}
}
I have this listing. FirstDictionaryand SecondDictionaryimplements DictionaryModel, this is a marker interface for using this solution.
Right now I would like to do this:
Class<FirstDictionary> clazz = Dictionaries.FIRST_DICTIONARY.clazz();
This is obviously not possible with this design, and I cannot figure out how to do this. Is there any way to do this? I have access to all the code, so I can change everything, including the interface (or even delete it).
I simplified all this, I want to say that every dictionary is a database table, and I have one common DAO for them (instead of a DAO for each dictionary), and now I have to give the result of every reading that I would like to avoid. I know that a general DAO is not a good idea (or a DAO at all).
Optional<DictionaryModel> entity = dao.getByValue(Dictionaries.FIRST_DICTIONARY, value);
DAO clazz(). , - .
, .