- public class LazyInit {
- private static volatile Map<String, String> cache;
- public static String get(String key) {
- if (cache == null) {
- synchronized (LazyInit.class) {
- if (cache == null) {
- Map<String, String> temp = new HashMap<>();
- temp.put("greeting", "hello");
- cache = temp;
- }
- }
- }
- return cache.get(key);
- }
- }