<div dir="ltr"><div style="font-family:monospace" class="gmail_default">Hello Brian,<br><br>Thank you for your response!<br><br>> We explored this topic<br>> ...<br>> but concluded that this failed the power-to-weight-ratio<br>> test<br><br>Makes a lot of sense. This is only ever going to apply to "magic methods".<br><br>> because usually you do not want to _refine_ an equals/toString/hashCode calculation, but instead broaden it<br><br>Makes a lot of sense. In my ~1.5 years of using records, this is the second time I have ever had the desire to refine the outcome of a "magic method".<br><br>> If you pull on this "string" a bit, the API that you<br>> would want here is complex and enormous, and has as many<br>> tuning knobs as a Lombok.<br><br>I see what you mean. Today, I wanted to include a derived value to the toString. What if I also wanted to include these derived values "inside" of the square brackets? Makes a lot of sense.<br><br>> Leave "future you" some comments for what you were<br>> thinking today.<br><br>Makes sense. I think the value of overriding toString is not very much in the long run, so rather than overriding, I'll just take the extra lap and insert the .map() call to my streams instead of being lazy.<br><br>Or I could do the "ugly" solution that Rémi came up with lol.<br><br>Thank you for your time and help!<br>David Alayachew<br></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 21, 2023 at 1:18 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@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>
<font size="4"><font face="monospace">We explored this topic
somewhat when designing the feature. <br>
<br>
When you override a method x, you can still delegate (via
super.x()) to the thing you override. We considered doing the
same here (delegating to default.x()), but concluded that this
failed the power-to-weight-ratio test, because usually you do
not want to _refine_ an equals/toString/hashCode calculation,
but instead broaden it (such as comparing arrays by contents
rather than by ==.) <br>
<br>
If you pull on this "string" a bit, the API that you would want
here is complex and enormous, and has as many tuning knobs as a
Lombok. So refactoring records that customize Object methods
becomes a higher-responsibility activity. Leave "future you"
some comments for what you were thinking today.<br>
<br>
<br>
</font></font><br>
<div>On 9/21/2023 1:00 PM, David Alayachew
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:monospace">Hello
Amber Dev Team,</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Let's
say I have a record like the following.</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">record
ComplexRecord(int blah /* and many more components */) {}</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Next,
let's say that I want to override my toString, to include some
derived information.</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Obviously,
putting the derived info into the toString is easy, but how do
I go about INCLUDING it with my original implementation of
toString that was magically created for me by Java?</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">If I
try to fully recreate my toString, I run the risk of it
becoming out-of-date upon refactor. Best I can come up with is
nesting another record with the toString overloaded. Also not
ideal.</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Thank
you for your time!</div>
<div class="gmail_default" style="font-family:monospace">David
Alayachew<br>
</div>
</div>
</blockquote>
<br>
</div>
</blockquote></div>