Best Practice: Java static non final variables

前端 未结 7 835
北荒
北荒 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:50

    When used as a cache, logging, statistics or a debug switch are the obvious reasonable uses. All private, of course.

    If you have mutable object assigned to a final field, that is morally the same as having a mutable field.

    Some languages, such as Fan, completely disallow mutable statics (or equivalent).

提交回复
热议问题