If instance variable is set final its value can not be changed like
public class Final {
private final int b;
Final(int b) {
this.b = b;
I think you are getting confused between "final" and "immutable" objects..
public class Final {
private final int b;
Final(int b) {
this.b = b;
}
int getFinal() {
return b = 8; // COMPILE TIME ERROR
}
}
Final means you cannot change the reference to the object. In case of primitives, it means you cannot change the value. So, when you try to set b to 8, you get a compile time error.
cc.setConditionMap(cacheMap);
public void setConditionMap(Map conditionMap) {
this.conditionMap = conditionMap;
}
In Java - "References to objects are passed by value" (As Bruce Eckel puts it in his book "Thinking in Java"). So, you are passing a copy of the reference. So, you have 2 references to the same cacheMap now.
So, you can change the cacheMap using any of the references. But you can reassign only the "copied" reference to another object, as it is not final (not the original one, the original one is final and CANNOT point to another object).