Set<T> () { Set<T> result = immutableSet; if (result == null) { synchronized (lock) { result = immutableSet; if (result == null) { // Expose the same set as immutable. It should be never modified again. Next add/remove operations will copy synchronizedSet result = Collections.unmodifiableSet(synchronizedSet); immutableSet = result; } } } return result; }