static method create inner class with generic

Viewed 63

It is a demo about inner class and generic type.

    class OuterClass<T> {

    public OuterClass() {
    }

    public static void main(String[] args) {
        new OuterClass<String>().new InnerAbstractClass() {
        };
    }

    public class InnerAbstractClass {
        T t;
        public void a() {

        }

    }
}
class OuterClassTest {
    public static void main(String[] args) {
        System.out.println(1);
        new OuterClass<String>().new InnerAbstractClass() {

        };
    }
}

Though it is compiled successfully, there is error info in main of OuterClass while no error in main of OuterClassTest. enter image description here I wonder why it is inconsistency. I'm using jdk8 and the newest IDEA.

3 Answers
Related