I have created an object which has a getter that returns a map. When ever I call getter and change the map from a calling object, why does it effect the original map. Even if it is declared as final. Why does this happen.
1>Is it because instead of returning a map object does the getter returns only object reference? 2>Does this happens to lists too?
Below code just for example not perfect code.
public class Worker{
private final Map<String, String> work;
public MatcherManager(Map<String, String> input) {
checkNotNull(input, "Input map not found");
his.workExperienceMatcher = input;
}
public Map<String, String> getWork() {
return work;
}