what is the sense of final ArrayList?

前端 未结 12 497
日久生厌
日久生厌 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:33

    final has a lot of consequences under multi threading.

    1. JMM clearly defines a final field's initialization completion is guaranteed.

    What's not clearly defined is:

    1. Compilers are free to reorder them across memory barriers.
    2. Compilers can always read a cached copy.

提交回复
热议问题