A static method creates an inner class with a common
This 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() {
};
}
}
Even though it compiled successfully, there is error information in the main OuterClass, and there is no error in the main OuterClassTest. I wonder why this is inconsistent. I am using jdk8 and the latest IDEA.
+3
source to share
3 answers
The code works. It even compiles (also in IntelliJ). The IDE just shows an error. Try your inner main class and it will work. Perhaps you could open an issue for JetBrains at https://youtrack.jetbrains.com/oauth?state=%2Fissues%2FIDEA
+1
source to share