Is it true that every inner class requires an enclosing instance?
The distinctions laid out in the question make perfect sense from the specification's standpoint:
an inner class has restrictions applied to it, which have nothing to do with the question of enclosing instances (it may not have static members, for example);
the concept of a static nested class is basically just about namespacing; these classes might rightfully be termed top-level, together with what we usually assume as top-level classes.
It just so happens that removing static
from a nested class declaration does two separate things at once:
- it makes the class require an enclosing instance;
- it makes the class inner.
We rarely think about inner as entailing restrictions; we only focus on the enclosing instance concern, which is much more visible. However, from the specification's viewpoint, the restrictions are a vital concern.
What we are missing is a term for a class requiring an enclosing instance. There is no such term defined by the JLS, so we have (unaware, it seems) hijacked a related, but in fact essentially different, term to mean that.