【发布时间】:2009-10-17 10:43:22
【问题描述】:
我继承了包含静态嵌套类的代码:
public class Foo {
// Foo fields and functions
// ...
private static class SGroup {
private static Map<Integer, SGroup> idMap = new HashMap<Integer, SGroup>();
public SGroup(int id, String type) {
// ...
}
}
}
从阅读 SO(例如Java inner class and static nested class)我相信这相当于两个单独文件中的两个单独的类:
public class Foo {
// Foo fields and functions
// ...
}
和
public class SGroup {
static Map<Integer, SGroup> idMap = new HashMap<Integer, SGroup>();
public SGroup(int id, String type) {
// ...
}
}
如果这是正确的,维护静态嵌套类结构有什么好处,还是我应该重构?
【问题讨论】: