Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些类在 //class Foo{ 之后定义了变量,在另一个类中创建了上面类的对象。一分钟后,我需要将 Foo 中的变量重置为默认值。我试图只创建新对象,没有任何反应。除了创建 setter 之外,还有其他方法吗?
您应该将这些默认值存储在其他地方,您无法恢复默认值。使用计时器重新加载这些变量。
// some untested code class A { final int x_DEFAULT = 0; int x = 0; void reloadVars() { x = x_DEFAULT; } A() { new Timer().scheduleAtFixedRate(new TimerTask() { public void run() { reloadVars(); } }, 60000, 60000); } }