java: is using a final static int = 1 better than just a normal 1?

后端 未结 7 1914
轻奢々
轻奢々 2020-12-11 06:47

I just saw a class (an big API module), where there is alot of stuff like

readParamString(Object params, int index)

and they have in that c

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 07:05

    By declaring with the keywords final static int, you will have a single instance of a variable that has the integer value of 1. An important point is that this value cannot change once declared with the keyword final. Otherwise, you can change the value of variable. You use the keywords final static if you don't want to change the variable value anywhere your code.

提交回复
热议问题