You could create a class like
class ReadOnlyMap<K, V> {
private final Map<K, V> map;
public ReadOnlyMap(Map<K, V> map) {
this.map = map;
}
public V get(Object key) {
return map.get(key);
}
// also implement size() method
// and everything else you want to expose
}
and use it as the return type of your method. Then your method would be
public ReadOnlyMap<String, Bar> getMap() {
return new ReadOnlyMap(aMap);
}
Beware that this won't hinder the caller to mutate the value objects, if they're not instances of immutable classes.