Why does the following code have a compile error:
Foo.java:
public abstract class Foo<T> {
public abstract T getInner();
}
MyFoo.java:
public class MyFoo extends Foo<MyFooInner> {
public static class MyFooInner {
}
public MyFooInner getInner() {
return new MyFooInner();
}
}
Compiling the second class results in:
MyFoo.java:1: cannot find symbol
symbol: class MyFooInner
public class MyFoo extends Foo<MyFooInner> {
^
1 error
Is there a way around this problem besides putting the inner class in its own file?
Use the following notation:
UPDATE: Static nested classes are effectively a top level class as specified here:
So, the only way you can refer to a static nested class is mentioning its parent class somewhere. Otherwise it is a reference to an imported class or to a class within the same package.
UPDATE: To explain it even more, another way to reference the class is to import it like this: