class - Is there a best practice for writing maps literal style in Java? -
class - Is there a best practice for writing maps literal style in Java? -
in short, if want write map of e.g. constants in java, in e.g. python , javascript write literal,
t<string,string> constants = { "constant_name_0": constant_value_0 , "constant_name_1": constant_value_1 , "constant_name_2": constant_value_2 , //... } ; is there class or preset object can utilize writing info construction that?
constants? i'd utilize enum.
public enum constants { name_1("value1"), name_2("value2"), name_3("value3"); private string value; constants(string value) { this.value = value; } public string value() { homecoming value; } } value e.g. name_2 can obtained follows:
string name2value = constants.name_2.value(); only give enum bit more sensible name, e.g. settings, defaults, etc, whatever name/value pairs actually represent.
java class object map literals
Comments
Post a Comment