<div dir="auto"><div>Understood. Thanks <span class="gmail_chip gmail_plusreply" dir="auto"><a href="mailto:scolebourne@joda.org" style="color:#15c;text-decoration:underline">@Stephen Colebourne</a></span>.<div dir="auto"><br></div><div dir="auto">And yes <span class="gmail_chip gmail_plusreply" dir="auto"><a href="mailto:attila.kelemen85@gmail.com" style="color:#15c;text-decoration:underline">@Attila Kelemen</a></span>, I agree that it being an annotation does make it less ideal. Plus, I lose out on other things that the compiler might one day give us, like exhaustiveness checking. All in all, it is still the best solution, but not one I am a fan of.</div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Dec 1, 2025, 4:55 AM Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com">attila.kelemen85@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">There are some other downsides as well: You will have to force your clients to specifically design their records to your API (i.e., annotate it, and configure the annotation processor). Though, in your case that is probably not too bad, because likely they want to design their DTO for your API anyway. The other downside is that you will have to write the IDE support as well (e.g., Idea's editor will have red curlys around without it). Which, aside from the additional maintenance cost, can be a problem for a user who is not allowed to install arbitrary IDE plugins. Also, compared to the original outline, you probably want an additional generic argument for the record type on `RecordComponentWrapper` for type safety.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank" rel="noreferrer">davidalayachew@gmail.com</a>> ezt írta (időpont: 2025. dec. 1., H, 1:53):<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 dir="ltr"><div style="font-family:monospace">Thanks Stephen.</div><div><br></div><div><div style="font-family:monospace">Hmmmmm, so this is definitely the best solution I have seen thus far. The only real downside is that the static final field has a different name than the actual record component. But I can probably fix that by making it an inner class or something, as opposed to sharing the same namespace as the record itself.</div><div style="font-family:monospace"><br></div><div style="font-family:monospace">Can you link me to the annotation code?</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Nov 30, 2025 at 4:05 PM Stephen Colebourne <<a href="mailto:scolebourne@joda.org" target="_blank" rel="noreferrer">scolebourne@joda.org</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">There is a way to do this, but it isn't pretty. Use annotation processing.<br>
<br>
@GeneratedRecordComponentInterface<br>
record User(String firstName, String lastName, ComplexObject<br>
complexColumn) implements UserColumns {}<br>
<br>
// annotation processor generates:<br>
public interface UserColumns {<br>
  public static final RecordComponentWrapper<String><br>
FIRST_NAME_COMPONENT = new RecordComponentWrapper(User.class,<br>
"firstName");<br>
  public static final RecordComponentWrapper<String><br>
LAST_NAME_COMPONENT = new RecordComponentWrapper(User.class,<br>
"lastName");<br>
  public static final RecordComponentWrapper<ComplexObject><br>
COMPLEX_COLUMN_COMPONENT = new RecordComponentWrapper(User.class,<br>
"complexColumn");<br>
}<br>
<br>
where `RecordComponentWrapper` is some suitable type-safe wrapper for<br>
record components.<br>
<br>
Although there is a string for each record component, it is in<br>
generated code, thus won't get out of sync.<br>
<br>
(This is the annotation processing equivalent to how Joda-Beans<br>
meta-properties have worked for many years)<br>
Stephen<br><br>
</blockquote></div>
</blockquote></div></div>
</blockquote></div></div></div>