Question about method references
David Alayachew
davidalayachew at gmail.com
Sat Nov 29 19:29:33 UTC 2025
Hello @core-libs-dev <core-libs-dev at openjdk.org>,
Let's say I have a record User(String first, String last) {}. That code
grants me User::first and User::last as accessor methods. Very cool.
I can access those accessor methods if I am given the class. It is a
trivial call from User.class ---> Class.getRecordComponents() --->
RecordComponent.getAccessor() ---> Method.invoke() ---> User::first/last.
It is very powerful.
But this only lets me go top-down. If I want to take a record accessor like
User::first and turn that into a record component, then that is not
something I can see how to do.
Is it impossible? There is a lot of value in being able to look at a method
reference and be able to see that class that that method being referenced
is contained within. For example, I would like to be able to look at
User::first, and be able to get the accompanying RecordComponent. And if
not that, then at least the accompanying java.lang.reflect.Method. Is that
possible?
Thank you for your time and consideration.
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251129/ecf4c328/attachment-0001.htm>
More information about the core-libs-dev
mailing list