简体   繁体   English

使用常量以外的静态类变量

[英]Use of static class variable other than constants

My professor wants a "non-trivial" answer to the question of "What are the uses of a static class variable, besides constants?"我的教授想要一个“非平凡”的答案来回答“静态类变量除了常量之外还有什么用途?”

Aside from constants, the only one I can think of is keeping a count of the objects that have been instantiated from the class.除了常量之外,我唯一能想到的就是保持从类中实例化的对象的数量。

A certainly non-trivial answer to this question can be found in this question在这个问题中可以找到对这个问题的肯定不平凡的答案

In short, they're used to keep global state for the class and make our lives as developers worse for fighting hard to reason about tests.简而言之,它们习惯于为类保持全局状态,并使我们作为开发人员的生活变得更糟,因为它们努力为测试推理而斗争。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM