<div dir="ltr"><div dir="ltr"><div>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><br></div><div>After all, it does this for <span style="font-family:monospace">Class</span> objects by providing us with <span style="font-family:monospace">Class</span> literals (remember in the old days you could only obtain them via <span style="font-family:monospace">Class.forName()</span>).</div><div><br></div><div>I have wondered the same thing, though I also appreciate that the devil is in the details.</div><div><br></div><div>For example, David's question could be addressed by adding <span style="font-family:monospace">Method</span> and <span style="font-family:monospace">Field</span> literals:</div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">public class Foo {</span></div><div style="margin-left:40px"><span style="font-family:monospace">    public static void meth(int x) { ... }</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">Method m = Foo::meth.method;</span></div><div style="margin-left:40px"><span style="font-family:monospace">m.invoke(123);</span></div><div><br></div><div>Of course, this is still imprecise because <span style="font-family:monospace">Method</span> is not generic and so this would fail if there were overloads, among other problems.</div><div><br></div><div>So I think the intuition is valid. Whether a practical solution exists is another question.</div><div><br></div><div>-Archie</div><div><br></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">chen.l.liang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>




<div dir="ltr">
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
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)">
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)">
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><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</div>