<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi David, before we investigate solutions, what is the problem you want to resolve?</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
If you want to obtain a Method on a record class, you can do recordClass.getMethod("variable") to find that accessor method.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Note that the Java Virtual Machine does not validate a record, that it may recognize a class with the record attribute but has no corresponding accessor methods or canonical constructor as a record class.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
-Chen</div>
<div id="appendonsend"></div>
<div><br>
<div style="font-family: Calibri; text-align: left; color: rgb(0, 0, 0); margin-left: 5pt; font-size: 10pt;">
Confidential- Oracle Internal</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amber-dev <amber-dev-retn@openjdk.org> on behalf of David Alayachew <davidalayachew@gmail.com><br>
<b>Sent:</b> Monday, December 1, 2025 10:09 AM<br>
<b>To:</b> Artyom Drozdov <artyomcool2@gmail.com><br>
<b>Cc:</b> amber-dev <amber-dev@openjdk.org><br>
<b>Subject:</b> Re: Reflection on records</font>
<div> </div>
</div>
<div>
<div dir="auto">
<div>Thank you Artyom.
<div dir="auto"><br>
</div>
<div dir="auto">This mailing list is actually my final stop. I already asked in multiple other places.</div>
<div dir="auto"><br>
</div>
<div dir="auto">And thanks for the suggestions about MethodHandles and InvokeDynamic. I think that might be overkill, so I'll probably just abandon the idea for now.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Either way, I sent a new message on the mailing list, asking for a new feature for records. All of the suggestions I've received thus far feel like trying to fit 10 pounds of dirt in a 5 pound bag. It feels like the language/compiler could step
in and provide us with better tools.</div>
<br>
<br>
<div class="x_gmail_quote x_gmail_quote_container">
<div dir="ltr" class="x_gmail_attr">On Mon, Dec 1, 2025, 9:57 AM Artyom Drozdov <<a href="mailto:artyomcool2@gmail.com">artyomcool2@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="auto">
<div dir="auto">Hello David,</div>
<div dir="auto"><br>
</div>
<div dir="auto"></div>
If you absolute sure that you need that, it is possible to extract method name and signature from method reference (and access via MethodHandle or Reflections later) by analyzing class file and InvokeDynamic instruction (you probably will need some time to
learn how it works if you are not familiar yet).
<div dir="auto"><br>
<div dir="auto">Personally, I'd prefer annotations + reflections + method handle approach (or drop the idea at all).</div>
<div dir="auto"><br>
</div>
<div dir="auto">I also think that resources like StackOverflow might suit your goal better than amber-dev mailing list)</div>
<div dir="auto"><br>
</div>
<div dir="auto">Regards,</div>
<div dir="auto">Artyom Drozdov<br>
<div dir="auto"><br>
<div class="x_gmail_quote" dir="auto">
<div dir="ltr" class="x_gmail_attr">пн, 1 дек. 2025 г., 15:47 David Alayachew <<a href="mailto:davidalayachew@gmail.com" rel="noreferrer noreferrer" target="_blank">davidalayachew@gmail.com</a>>:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="auto">
<div>Understood. Thanks <span class="x_gmail_chip x_gmail_plusreply" dir="auto"><a href="mailto:scolebourne@joda.org" rel="noreferrer noreferrer noreferrer" target="_blank" style="color:#15c; text-decoration:underline">@Stephen Colebourne</a></span>.
<div dir="auto"><br>
</div>
<div dir="auto">And yes <span class="x_gmail_chip x_gmail_plusreply" dir="auto"><a href="mailto:attila.kelemen85@gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank" style="color:#15c; text-decoration:underline">@Attila Kelemen</a></span>, I agree
that it being an annotation does make it less ideal. Plus, I lose out on other things that the compiler might one day give us, like exhaustiveness checking. All in all, it is still the best solution, but not one I am a fan of.</div>
<br>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Mon, Dec 1, 2025, 4:55 AM Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank">attila.kelemen85@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div dir="ltr">There are some other downsides as well: You will have to force your clients to specifically design their records to your API (i.e., annotate it, and configure the annotation processor). Though, in your case that is probably not too bad, because
likely they want to design their DTO for your API anyway. The other downside is that you will have to write the IDE support as well (e.g., Idea's editor will have red curlys around without it). Which, aside from the additional maintenance cost, can be a problem
for a user who is not allowed to install arbitrary IDE plugins. Also, compared to the original outline, you probably want an additional generic argument for the record type on `RecordComponentWrapper` for type safety.</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">David Alayachew <<a href="mailto:davidalayachew@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">davidalayachew@gmail.com</a>> ezt írta (időpont: 2025. dec. 1., H, 1:53):<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:monospace">Thanks Stephen.</div>
<div><br>
</div>
<div>
<div style="font-family:monospace">Hmmmmm, so this is definitely the best solution I have seen thus far. The only real downside is that the static final field has a different name than the actual record component. But I can probably fix that by making it an
inner class or something, as opposed to sharing the same namespace as the record itself.</div>
<div style="font-family:monospace"><br>
</div>
<div style="font-family:monospace">Can you link me to the annotation code?</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Sun, Nov 30, 2025 at 4:05 PM Stephen Colebourne <<a href="mailto:scolebourne@joda.org" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">scolebourne@joda.org</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
There is a way to do this, but it isn't pretty. Use annotation processing.<br>
<br>
@GeneratedRecordComponentInterface<br>
record User(String firstName, String lastName, ComplexObject<br>
complexColumn) implements UserColumns {}<br>
<br>
// annotation processor generates:<br>
public interface UserColumns {<br>
public static final RecordComponentWrapper<String><br>
FIRST_NAME_COMPONENT = new RecordComponentWrapper(User.class,<br>
"firstName");<br>
public static final RecordComponentWrapper<String><br>
LAST_NAME_COMPONENT = new RecordComponentWrapper(User.class,<br>
"lastName");<br>
public static final RecordComponentWrapper<ComplexObject><br>
COMPLEX_COLUMN_COMPONENT = new RecordComponentWrapper(User.class,<br>
"complexColumn");<br>
}<br>
<br>
where `RecordComponentWrapper` is some suitable type-safe wrapper for<br>
record components.<br>
<br>
Although there is a string for each record component, it is in<br>
generated code, thus won't get out of sync.<br>
<br>
(This is the annotation processing equivalent to how Joda-Beans<br>
meta-properties have worked for many years)<br>
Stephen<br>
<br>
</blockquote>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>