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.
I wonder why it is inconsistency.
I'm using jdk8 and the newest IDEA.
The code works. It even compiles (also in IntelliJ). The IDE just shows an error. Try to execute your inner main class and this will work. Maybe you could open up an issue for JetBrains at https://youtrack.jetbrains.com/oauth?state=%2Fissues%2FIDEA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With