static final field in public nested class

A inner class (non-static nested class) can not have any static methods. because

An inner class is implicitly associated with an instance of its outer class, it cannot define any static methods itself.

For an outer class Foo, you can access a static method test() like this:

Foo.test();

For a static inner class Bar , you can access its static method innerTest() like this:

Foo.Bar.innerTest();

However, if Bar is not static, there is now no static way to reference the method innerTest(). Non-static inner classes are tied to a specific instance of their outer class.


The inner class cannot have static methods... If you want to have it, you need to define Bar as static as well.

Otherwise, the field must be declared as non-static.

Tags:

Java

Eclipse