Why final instance class variable in Java?

后端 未结 11 736
南方客
南方客 2020-12-09 05:13

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; 
         


        
11条回答
  •  执念已碎
    2020-12-09 05:24

    When a reference is final, it cannot be linked to any other object.

    The values of the object can be changed, so you can add values to the map, but cannot change the object of the map.

提交回复
热议问题