Are final static variables thread safe in Java?

前端 未结 8 887
盖世英雄少女心
盖世英雄少女心 2020-12-13 06:40

I\'ve read around quite a bit but haven\'t found a definitive answer.

I have a class that looks like this:

    public class Foo() {

        private          


        
8条回答
  •  遥遥无期
    2020-12-13 07:20

    Aren't you are actually asking if the static initialization of sharedData is thread safe and only executed once?

    And yes, that is the case.

    Of course many people here have correctly pointed out that the contents of sharedData can still be modified.

提交回复
热议问题