简体   繁体   English

Java static class 内部 class

[英]Java static class inside inner class

Problem: Java allows static nested classes inside an outer class, and allows further static nested classes inside those static nested classes. Problem: Java allows static nested classes inside an outer class, and allows further static nested classes inside those static nested classes. It also allows non-static ("inner") classes nested inside an outer class.它还允许嵌套在外部 class 内的非静态(“内部”)类。 But for some reason I can't make a static class nested inside an inner class.但由于某种原因,我无法将 static class 嵌套在内部 class 内。

Why does the following code fail to compile?为什么下面的代码编译失败?

class Outer
{
    // OK
    static class Static
    {
        // OK
        static class StaticDoubleNested
        {
        }
    }

    // OK
    class Inner
    {
        // BAD
        // "error: modifier static not allowed here"
        static class StaticDoubleNested
        {
        }
    }
}

As your inner class and outer class are calling the same (static) methode "static class StaticDoubleNested" coulde it be that the inner class methode is only Overriding the outer class methode? As your inner class and outer class are calling the same (static) methode "static class StaticDoubleNested" coulde it be that the inner class methode is only Overriding the outer class methode?

If that`s the case then interfaces or abstract classes will be your choice.如果是这种情况,那么接口或抽象类将是您的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM