Hello! JLS for records says that record component getter is named in the same way as the corresponding field, and this is completely fine for Java language. However it's unclear for me which approach is best for the JVMS. I see several options:
- No direct link between record component and the corresponding getter method at all. A class is free to have an arbitrary named getter or provide no getter at all. Reflection API believes that there's a getter named after the record component and may fail for custom generated classes, but otherwisely these classes work fine. - Strict requirement that a class must contain a method named exactly like a record component and having no parameters and exactly the same return type as the record component type, otherwise the class verification fails. - Flexible link: a record component has a new required attribute like "Getter" which links an arbitrarily named method which has no parameters and exactly the same return type as the record component type. The latter option may be more friendly for JVM languages other than Java: they may also produce class files with the record components linking them to the getter names which are traditionally generated in given language for data classes or case classes (usually "getName" for "name" component, etc.). In this case both bytecode analysis tools and reflection-based frameworks could process Java records and non-Java data-classes/case-classes uniformly. What do you think? With best regards, Tagir Valeev.