Q:
I have just found a static inner interface in our code-base.
- class Foo {
- public static interface Bar {
- /* snip */
- }
- /* snip */
- }
I have never seen this before. The original developer is out of reach. Therefore I have to ask SO:
What are the semantics behind a static interface? What would change, if I remove the static? Why would anyone do this?
A:
An inner interface has to be static in order to be accessed. The interface isn't associated with instances of the class, but with the class itself, so it would be accessed with Foo.Bar, like so:
- public class Baz implements Foo.Bar {
- ...
- }
In most ways, this isn't different from a static inner class.