Saturday, January 2, 2010

Instantiate and initialize a HashMap in one statement

ever thought about having your constants inside one hashmap that you can call statically from any where in your program, well , I've googled to find this is totally acceptable, check this code


You would be better off w/ a package private or inner class (inner class is easier to type but becomes a small part in the interface) that has methods and does the same initialization.


Just a note, unmodifiableMap for an interface instance is also a good tip. The idiom below can initialize more sophisticated structures and even read from the disk (e.g. some localization data, etc)


That's it for this matter , till we meet again