相关疑难解决方法(0)

我应该将Java中的静态嵌套类重构为单独的类吗?

我继承了包含静态嵌套类的代码:

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)

如果这是正确的,维护静态嵌套类结构有什么好处,还是应该重构?

java static nested class

2
推荐指数
2
解决办法
1750
查看次数

标签 统计

class ×1

java ×1

nested ×1

static ×1