[英]Can outer class be defined as static and enclose inner static class?
It correct to define an outer class as static which have inside also a static class? 将外部类定义为静态内部也是静态类是正确的吗? Only one instance of outer and inner classes is needed.
只需要一个外部和内部类的实例。 Can outer class be abstract and it's enclosed class be static?
外部类可以是抽象的,它的封闭类是静态的吗?
No, a top level class can't be static. 不,顶级课程不能是静态的。 The meaning of "static" in a class declaration is only relevant to nested classes.
类声明中“static”的含义仅与嵌套类有关。 You can certainly have a static nested class within an abstract class though.
但是,您当然可以在抽象类中拥有静态嵌套类。
From the JLS section 8.1.1 : 从JLS第8.1.1节 :
The modifier static pertains only to member classes (§8.5.1), not to top level or local or anonymous classes.
修饰符static仅适用于成员类(第8.5.1节),不适用于顶级或本地或匿名类。
Note that if you want "only one instance" of a class, you should potentially make it a singleton - which is entirely separate, and not something which affects the class declaration itself. 请注意,如果您只想要一个类的“只有一个实例”,那么您应该将它设为一个单例 - 这是完全独立的,而不是影响类声明本身的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.