<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Brian Goetz" <brian.goetz@oracle.com><br><b>To: </b>"Archie Cobbs" <archie.cobbs@gmail.com><br><b>Cc: </b>"Chen Liang" <chen.l.liang@oracle.com>, "David Alayachew" <davidalayachew@gmail.com>, "amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Monday, December 1, 2025 7:37:56 PM<br><b>Subject: </b>Re: Reflection on records<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
Let me replay some analysis that was done on this topic in the past.  
<div class=""><br class="">
</div>
<div class="">There are two separate things going on here:</div>
<div class=""><br class="">
</div>
<div class=""> - Can we use symbolic constants instead of string constants to do reflective lookups</div>
<div class=""> - Can we have more kinds of symbolic reflective constants (field literals, method literals, record component literals, method handle literals, etc.)</div>
<div class=""><br class="">
</div>
<div class="">The first one is more shallow; David is exploiting a special case of records where (a) there is already a method reference form for accessors, which could potentially be bootstrapped into service here and (b) very luckily, the shape of all such
 accessor method references vary only parametrically in shape.  So one could write a method:</div>
<div class=""><br class="">
</div>
<div class="">    interface AccessorShape<T, U> { </div>
<div class="">        U access(T t);</div>
<div class="">    }</div>
<div class=""><br class="">
</div>
<div class="">    <R extends Record, U> RecordComponent component(Accessor<R, U> c) { … }</div>
<div class=""><br class="">
</div>
<div class="">Which would allow us to say </div>
<div class=""><br class="">
</div>
<div class="">    RecordComponent rc = component(Foo::component)</div>
<div class=""><br class="">
</div>
<div class="">Where the parameter is a method reference but from which we can strip-mine the name and type and turn it into a component lookup.  That’s a clever trick, and there is no intrinsic reason why we couldn’t do this, but it doesn’t scale beyond this
 particular case.  Field and method lookups would still use strings and could fail at runtime for all the reasons.  </div>
<div class=""><br class="">
</div>
<div class="">The second is one that was explored fairly deeply during Lambda.  Reflective literals for jlr.{Field,Method,Constructor} are an obvious move, and have a few challenges, some of which are workable, but the biggest of which is: overloading.  With
 method reference targeted at functional interfaces, the functional interface provides a signature shape with which we can do overload selection.  But if we had an overloaded method m, then</div>
<div class=""><br class="">
</div>
<div class="">    Method m = Foo::m</div>
<div class=""><br class="">
</div>
<div class="">We have no information with which to select the proper m.  (Please, don’t take this as an invitation for a syntax discussion; they’ve all been explored, and besides, there are deeper problems here than syntax.)  </div></blockquote><div><br></div><div>yes,</div><div>the current status quo is that IDEs (at least IntelliJ) are able to typecheck the creation of Method, Field, MethodHandle, VarHandle, etc so it's not in the language but it's good enough.</div><div><br data-mce-bogus="1"></div><div>We still have to make all those pesky exceptions unchecked but that's another story ...</div><div><br data-mce-bogus="1"></div><div>Rémi</div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div class=""><br class="">
<div><br class="">
<blockquote class="">
<div class="">On Dec 1, 2025, at 12:13 PM, Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" class="" target="_blank">archie.cobbs@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="">I'm guessing what underlies David's question is this thought: Why can't the compiler provide more compile-time checking of Field and Method reflection objects?</div>
<div class=""><br class="">
</div>
<div class="">After all, it does this for <span style="font-family:monospace" class="">
Class</span> objects by providing us with <span style="font-family:monospace" class="">
Class</span> literals (remember in the old days you could only obtain them via <span style="font-family:monospace" class="">
Class.forName()</span>).</div>
<div class=""><br class="">
</div>
<div class="">I have wondered the same thing, though I also appreciate that the devil is in the details.</div>
<div class=""><br class="">
</div>
<div class="">For example, David's question could be addressed by adding <span style="font-family:monospace" class="">
Method</span> and <span style="font-family:monospace" class="">Field</span> literals:</div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class=""><br class=""></span></div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class="">public class Foo {</span></div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class="">    public static void meth(int x) { ... }</span></div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class="">}</span></div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class=""><br class=""></span></div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class="">Method m = Foo::meth.method;</span></div>
<div style="margin-left:40px" class=""><span style="font-family:monospace" class="">m.invoke(123);</span></div>
<div class=""><br class="">
</div>
<div class="">Of course, this is still imprecise because <span style="font-family:monospace" class="">
Method</span> is not generic and so this would fail if there were overloads, among other problems.</div>
<div class=""><br class="">
</div>
<div class="">So I think the intuition is valid. Whether a practical solution exists is another question.</div>
<div class=""><br class="">
</div>
<div class="">-Archie</div>
<div class=""><br class="">
</div>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, Dec 1, 2025 at 10:46 AM Chen Liang <<a href="mailto:chen.l.liang@oracle.com" target="_blank" class="">chen.l.liang@oracle.com</a>> wrote:<br class="">
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="">
<div dir="ltr" class="">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt;" class="">
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;" class="">
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;" class="">
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>
</div>
</blockquote>
</div>
<span class="gmail_signature_prefix">-- </span><br class="">
<div dir="ltr" class="gmail_signature">Archie L. Cobbs<br class="">
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div><br></blockquote></div></div></body></html>