Nested Classes, Part 3
Subject:   Uhh... Map.Entry?
Date:   2004-06-11 15:24:01
From:   Sean_Reilly
>Ultimately, nesting classes or interfaces
>inside other interfaces should probably be
>blocked by the compiler because using them
>makes no sense in object-oriented programming

An excellent example of a nested interface that should be a nested interface is Map.Entry.

If Map.Entry was expressed any other way (such as a seperate interface entirely), then people might refer to Map.Entry outside of the context of a Map, which is clearly not what the designers of the Collections API wanted. If it wasn't mentioned at all, then the semantic definition of a map as "A collection of key-value pairs" can't be encoded in the interface. So the only remaining alternative is to have either a nested class, or a nested interface.

I'm reasonable sure that describing any higher-order constraint in an interface will require more than one interface. In the cases where the higher-order interface isn't particularly sensible outside of the lower-order one (as a map entry isn't useful outside of the context of a map), it should be expressed as a nested interface.

I like using Maps, so I'm pretty glad that the compiler does allow this behavior ;)