nest syntax proposal
brian.goetz at oracle.com
Sun Jan 20 23:07:01 UTC 2019
> And they understand auxiliary classes. Let’s work with the familiar concepts.
> but your solution seems tailored to sealed types, what if i have several record classes with no common abstract type, how it works ?
> and again there is no refactoring between a classical interface and a sealed interface, something we should try offer.
Indeed, I think there are two things here. We can choose to address one or both or neither, with the obvious tradeoffs.
Issue #1 is that sealed types naturally form a family, you’re going to switch over them, etc, like enums, and we want the same (or more) nice treatment as we currently get with enums in switch. So it makes sense to define them all in one place; indeed, that should be the common case. Doing something with import helps here, but as you say, it is more specific to sealed types. On the other hand, enums and sealed types are related, so mirroring the special treatment that enums get (maybe even giving both a little more) is a low-energy-state solution.
Issue #2 is that with records, one line per file starts to seem silly. This has a lot of overlap with #1, but not entirely. You could argue its a more general solution, and maybe we like that, but maybe we don’t. It surely is more intrusive — affecting the existing semantics of auxiliary classes, and dramatically increasing the use of auxiliary classes (which, BTW, we’ve banned from the JDK source base because they make life very hard for build tooling), etc. It’s a bigger hammer.
Its also possible we do nothing here, and let users nest the subtypes and clients just say “import static SealedType.*”. That’s the least intrusive, so we should compare cost/benefit against that baseline.
More information about the amber-spec-observers