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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -