Declare final variable, but set later

后端 未结 7 1554
梦毁少年i
梦毁少年i 2020-12-09 01:49

I know this is fairly simple topic, but I really want to wrap my head around it.

This is what I\'m trying to do, but it doesn\'t like the final modifier. Is there an

7条回答
  •  萌比男神i
    2020-12-09 01:59

    private final long mId;
    

    final reference cann't be modified at runtime as per java spec. So, once you declared it as final, mId can't point to something else throughout its lifetime (Unless you use reflection (or) wrap the value in object and modify it through other reference).

提交回复
热议问题