Java changing value of final array element

后端 未结 4 690
长情又很酷
长情又很酷 2021-01-14 08:17

I am trying to understand what happens if I reassign a value to array element which is final, this is the code :

public class XYZ {
    private static final          


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 08:54

    My response is same as the others that "final" only prevents the variable from pointing to a new object, it does not prevent the object itself updates its members.

    Additional response about you mention that the output seems to append the string, but it is not, because you have a print statement before the assignment, and one after the assignment.

提交回复
热议问题