I need to lazily initialize a map and its contents. I have the below code till now:
class SomeClass {
private Map someMap = null;
I think TimB explained most of the options very well, but I think the quickest and most obvious answer would be to create it when the class instance is instantiated.
class SomeClass {
private final Map someMap = new HashMap();
public String getValue(String key) {
return someMap.get(key); // the key might not exist even after initialization
}
}