Final variable manipulation in Java

前端 未结 11 749
无人及你
无人及你 2020-11-28 23:28

Could anyone please tell me what is the meaning of the following line in context of Java:

final variable can still be manipulated unless it\'s immut

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 23:44

    There two things Final variable and final reference variable.

    If we are using final keyword with primitive data type we can't change anything. But if we are using final keywprd with non - primitive data, we can change it's properties like:

    1. If you are using a final keyword with primitive types of the variable (int, float, char, etc) then you can’t change the value of a final variable once it is initialized. So, we should initialize it.

    2. If you are using a final keyword with non-primitive variables (By means of non-primitive variables are always references to objects in Java), the member of the object can be changed. It means we can change the properties of the object, but we can’t change to refer to any other object.

    https://javagoal.com/final-keyword-in-java/

提交回复
热议问题