我继承了包含静态嵌套类的代码:
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) {
// ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
从阅读SO(例如Java内部类和静态嵌套类),我相信这相当于两个单独文件中的两个单独的类:
public class Foo {
// Foo fields and functions
// ...
}
Run Code Online (Sandbox Code Playgroud)
和
public class SGroup {
static Map<Integer, SGroup> idMap = new HashMap<Integer, SGroup>();
public SGroup(int id, String type) {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
如果这是正确的,维护静态嵌套类结构有什么好处,还是应该重构?