Question: Hi  

Is the class below threadsafe?

```
class ImmutablePossiblyThreadsafeClass<K, V> {

    private final Map<K, V> map;

    public ImmutablePossiblyThreadsafeClass(final Map<K, V> map) {
        this.map = new HashMap<K, V>();

        for (Entry<K, V> entry : map.entrySet()) {
            this.map.put(entry.getKey(), entry.getValue());
        }
    }

    public V get(K key) {
        return this.map.get(key);
    }
}

```

Answer: 
Assuming that nothing changes the map field after construction (since you've named it "immutable" I guess that's the idea) AND the map provided as constructor argument is not altered during construction, that is a thread-safe class.

Mind that there are easier ways of copying entries from one map to another than iteration. You might also want to look at some of the methods in [Collections](http://download.oracle.com/javase/6/docs/api/java/util/Collections.html) to create immutable versions of collections. You'd first have to copy the map, of course, since the underlying map could still be changed. The "unmodifiable\*" methods only return a **view** of a collection.
I think it is thread-safe the way it is. You've created (effectively) a copy of the input `map` and are doing only read-only operations on it. I've sort of always held the belief that immutable classes are inherently thread-safe. But be aware that unless your `K` and `V` classes are immutable, you could still run into thread safety issues.

You could also replace it with:

```
Map<K, V> m = Collections.unmodifiableMap(Collections.synchronizedMap(map));

```