Reflection on records

Tagir Valeev amaembo at gmail.com
Mon Dec 1 10:22:31 UTC 2025


I think this will surely be possible for RecordComponents with code
reflection (project Babylon), using the syntax you propose.

You can create a quotable function like this:

import jdk.incubator.code.*;

@Reflect
@FunctionalInterface
interface Accessor {
  Object get(Record r);
}

Then create something like (just a sketch, sorry, I have no time now to
provide a full-fledged sample):

static RecordComponent foo(Accessor acc) {
  Quoted q = Op.ofQuotable(acc).orElseThrow();
  // extract a method handle from q using Babylon API
  // unreflect it and find the corresponding RecordComponent
}

With best regards,
Tagir Valeev

On Sat, Nov 29, 2025 at 8:45 PM David Alayachew <davidalayachew at gmail.com>
wrote:

> Hello @amber-dev <amber-dev at openjdk.org>,
>
> I asked this on core-libs-dev already, but I figured I should ask here too.
>
> Let's say I have some record User(String firstName, String lastName) {}.
>
> Is there any possible way for me to do the following?
>
> java.lang.reflect.RecordComponent firstName = foo(User::firstName);
>
> I'll even accept this.
>
> java.lang.reflect.Method lastName = foo(User::lastName);
>
> Thank you for your time and consideration.
> David Alayachew
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20251201/a73a9da1/attachment.htm>


More information about the amber-dev mailing list