Are final static variables thread safe in Java?

前端 未结 8 895
盖世英雄少女心
盖世英雄少女心 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:02

    No. Except if they are immutable.

    The only thing they do is

    • Be class level accesible
    • Avoid the reference to be changed.

    Still if your attribute is mutable then it is not thread safe.

    See also: Do we synchronize instances variables which are final?

    It is exactly the same except they are class level.

提交回复
热议问题