what is the sense of final ArrayList?

前端 未结 12 491
日久生厌
日久生厌 2020-11-29 00:16

Which advantages/disadvantages we can get by making ArrayList (or other Collection) final? I still can add to ArrayList new elements, remove elements and update it. But what

12条回答
  •  离开以前
    2020-11-29 00:41

    Essentially what you are trying to achieve here is making the list immutable I guess. However when you mark the list reference final it implies that the reference cant be pointed to any other list object other than this.

    If you want a final (immutable) ArrayList go for Collections class's utility method Collections.unmodifaibleList( list ) instead.

提交回复
热议问题