> On Jan 9, 2020, at 9:03 AM, Brian Goetz <brian.go...@oracle.com> wrote: > >> FWIW, I think it's helpful for case analysis to flatten the list of things >> that can be nested/contain nested things as follows: >> - top-level/static classes >> - inner classes* (I always forget whether this includes local classes, but >> turns out it does) >> - interfaces >> - records >> - enums >> - annotation types >> - static methods/initializers >> - instance methods/local methods/constructors/instance initializers* >> >> The proposal is that each one of these can be nested in any of these. > > Of course, some of these don't make sense, such as "constructors in field > initializers", so it's not quite as simple as that, but yes, we should seek > to bust the _gratuitous_ restrictions.
Yeah, thinking a bit more, I guess I'd refine my list like so: Type declarations: - top-level/static classes - inner classes* - interfaces - records - enums - annotation types Method declarations: - static methods - instance/local methods* - static initializers - instance initializers/constructors* Variable declarations (leaf nodes, not containers): - instance/local variables* - static variables And then "anything can be nested inside of anything" has the following exceptions: - interfaces can't directly contain instance initializers/constructors, instance/local variables, or inner classes (maybe) - records can't directly contain instance/local variables - annotation types can't directly contain things prohibited in interfaces, or instance/local methods (maybe) - method declarations of any kind can't directly contain static initializers, instance initializers/constructors, static methods (maybe), or static variables (maybe) So, not quite "anything goes", but a much shorter and more refined list of prohibitions than we had previously.