Global variables in Java

后端 未结 24 2082
青春惊慌失措
青春惊慌失措 2020-11-22 11:56

How do you define Global variables in Java ?

24条回答
  •  时光取名叫无心
    2020-11-22 12:25

    There is no such thing as a truly global variable in Java. Every static variable must belong to some class (like System.out), but when you have decided which class it will go in, you can refer to it from everywhere loaded by the same classloader.

    Note that static variables should always be protected when updating to avoid race conditions.

提交回复
热议问题