This is probably the case using lazy map loading.
But you will need to set inputFileName before calling getValue() for the first time. This will be done in your initialization code for applications. (Or you may have a static method to install it.)
This indicates the advantage of lazy loading. You don't have to have a file name until you call getValue() for the first time. Using a static initializer, you should get the file name stored somewhere outside the class so that it can be used to load data when the class loads (but after the initialization of the static fields.
public static String inputFileName = null; public static String getValue(String key) { if (map == null) { map = = new HashMap<String, String>();
If your code is multithreaded, let me know and I will comment on synchronization issues.
Alternative
You can also use Spring to introduce a map and build it in some other class - MapBuilder , for example.
source share