<div dir="auto"><div>Symbolic reflective constants is a something I was always dreamed about.</div><div dir="auto">I'm currently using old-but-gold CLDC HI for my pet project and I'm really struggling without class literals (so I'll probably add them).</div><div dir="auto">The same way I feel about fields/methods references. I suppose it was discussed before, but it would be great to know, why can't we ask user for the full signature? Like:</div><div dir="auto"><br></div><div dir="auto">Method m = Foo::method[String, int];</div><div dir="auto"><br></div><div dir="auto">Or even (argument names here is an optional hint for the reader and IDE/linters):</div><div dir="auto"><br></div><div dir="auto">Method m = Foo::method[String name, int size];</div><div dir="auto"><br></div><div dir="auto">Of course, the syntax is not something that really worth to discuss here. Probably, we might want to specify the return type as well, but, again, that's about syntax.</div><div dir="auto"><br></div><div dir="auto"><br><div class="gmail_quote gmail_quote_container" dir="auto"><div dir="ltr" class="gmail_attr">пн, 1 дек. 2025 г., 19:38 Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div style="word-wrap:break-word;line-break:after-white-space">
Let me replay some analysis that was done on this topic in the past.  
<div><br>
</div>
<div>There are two separate things going on here:</div>
<div><br>
</div>
<div> - Can we use symbolic constants instead of string constants to do reflective lookups</div>
<div> - Can we have more kinds of symbolic reflective constants (field literals, method literals, record component literals, method handle literals, etc.)</div>
<div><br>
</div>
<div>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><br>
</div>
<div>    interface AccessorShape<T, U> { </div>
<div>        U access(T t);</div>
<div>    }</div>
<div><br>
</div>
<div>    <R extends Record, U> RecordComponent component(Accessor<R, U> c) { … }</div>
<div><br>
</div>
<div>Which would allow us to say </div>
<div><br>
</div>
<div>    RecordComponent rc = component(Foo::component)</div>
<div><br>
</div>
<div>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><br>
</div>
<div>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><br>
</div>
<div>    Method m = Foo::m</div>
<div><br>
</div>
<div>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>
<div><br>
<div><br>
<blockquote type="cite">
<div>On Dec 1, 2025, at 12:13 PM, Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank" rel="noreferrer">archie.cobbs@gmail.com</a>> wrote:</div>
<br>
<div>
<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" rel="noreferrer">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">
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">
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">
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>
</div>
</blockquote>
</div>
<br>
</div>
</div>

</blockquote></div></div></div>