亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - abstract inner class + generics
給我你的懷抱
給我你的懷抱 2017-05-17 10:00:28
0
1
988

Simple inner class usage:

public class OuterClass {
    public OuterClass() {
    }

    public abstract class InnerAbstractClass {
        public void a() {

        }
        public abstract void absMethod();
    }
    
    public void test() {
        new OuterClass().new InnerAbstractClass() {
            public void absMethod() {

            }
        };
    }
    
    public static void main(String[] args) {

        new OuterClass().new InnerAbstractClass() {
            public void absMethod() {

            }
        };
    }
}

Add generics to the above example

public class OuterClass<T> {
    public OuterClass() {
    }

    public abstract class InnerAbstractClass {
        public void a() {

        }
        public abstract void absMethod();
    }

    public void test() {
        new OuterClass().new InnerAbstractClass() {
            public void absMethod() {

            }
        };
    }

    public static void main(String[] args) {

        new OuterClass().new InnerAbstractClass() {
            public void absMethod() {

            }
        };
    }
}

Call the inner class in the test method and compile correctly. An error is reported in the main method, cannot be referenced from a static context.
No error will be reported if an internal class is called in another newly created class

public class OuterClassTest {
    public static void main(String[] args) {
        new OuterClass().new InnerAbstractClass() {
            public void absMethod() {

            }
        };
    }
}

Why? ? ?

給我你的懷抱
給我你的懷抱

reply all(1)
巴扎黑

Haha, click on the unhelpful person, copy the code and run it yourself, it will compile without any problem! no problem!

If you don’t know how to use IDE, just use javac

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template