5 ms·
So one thing peculiar in Java is public records have to be in their own files. Now I wanted to treat records as less ceremonial than classes to organize code. I
by geodel 5y ago
So one thing peculiar in Java is public records have to be in their own files. Now I wanted to treat records as less ceremonial than classes to organize code. I'd have liked to have a dozen or so records in a file along with some basic operations on them but it is not possible have multiple records without that many files.
I know the answer is always use IDE and all but it causes more context switches than scrolling a bit to see types I created.
- smarks 5y agoIf you have a bunch of related records you can make them public and nested within a top-level public class. You could also throw some static utility or factory methods in there too.
- cema 5y agoSure, but that's still ceremony.
- samus 5y agoIt's a core restriction of Java that there can only be one public class in each file. Nesting records inside a class would solve the issue. It's not that pretty though because only lower-casing the class name would create the illusion of it being a package.