First off, apologies if this is a duplicate of an existing question. Wasn’t precisely sure how to word my question so that may be why I haven’t found a clear answer yet. Essentially, I want to know if the following is considered good practice or if there is a better way to do this:
public enum ExampleEnum {
ENTRY_1(new ExampleCodedValue("entry1", "comment1")),
ENTRY_2(new ExampleCodedValue("entry2", "comment2")),
ENTRY_3(new ExampleCodedValue("entry3", "comment3")),
ENTRY_4(new ExampleCodedValue("entry4", "comment4"));
private ExampleCodedValue codedValue;
ExampleEnum(ExampleCodedValue codedValue) {
this.codedValue = codedValue;
}
public ExampleCodedValue getCodedValue() {
return codedValue;
}
}
class ExampleCodedValue {
private final String code;
private final String comment;
ExampleCodedValue(String code, String comment) {
this.code = code;
this.comment = comment;
}
}
That’s a perfectly reasonable way to do it, however, couldn’t you do this: