Best Practice: Java static non final variables

前端 未结 7 833
北荒
北荒 2020-12-08 15:03

In Java, when should static non final variables be used?

For example

private static int MY_VAR = 0;

Obviously we are not talking ab

相关标签:
7条回答
  • 2020-12-08 15:55

    I think wrapping your statics and providing access via singletons (or at a minimum via static methods) is generally a good idea, since you can better control access and avoid some race condition and synchronization issues.

    0 讨论(0)
提交回复
热议问题