Java: Multiple class declarations in one file

My suggested name for this technique (including multiple top-level classes in a single source file) would be “mess”. Seriously, I don’t think it’s a good idea – I’d use a nested type in this situation instead. Then it’s still easy to predict which source file it’s in. I don’t believe there’s an official term for this approach though.

As for whether this actually changes between implementations – I highly doubt it, but if you avoid doing it in the first place, you’ll never need to care 🙂

Leave a Comment