You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by William Degrange <wi...@outlook.com> on 2025/09/29 11:43:12 UTC
Use getters for boolean fields in ToStringStyle for 'dynamic' behavior
Hi all,
I would like to propose a small improvement in ToStringStyle.
Currently, some boolean fields in ToStringStyle are accessed directly in ToStringBuilder instead of through their getters. This prevents subclasses from overriding the behavior.
My proposal is to switch the code to use the getters instead of direct field access. This would allow subclasses to provide dynamic behavior, for example, returning values based on a logger’s debug level, without needing to create a new ToStringStyle instance for every toString() call.
Before opening a PR, I wanted to discuss this with the community to confirm that this approach is acceptable.
Any thoughts or concerns?
Note : this is already the case for the 'useIdentityHashCode' field.
Thanks,
William
Re: Use getters for boolean fields in ToStringStyle for 'dynamic' behavior
Posted by Gary Gregory <ga...@gmail.com>.
Hello William,
Thank you for reaching out.
Feel free to provide a PR on GitHub with unit tests so we can see what
impact this may have regarding possibly breaking existing call sites.
Thank you,
Gary
On Mon, Sep 29, 2025, 10:38 William Degrange <wi...@outlook.com>
wrote:
> Hi all,
> I would like to propose a small improvement in ToStringStyle.
> Currently, some boolean fields in ToStringStyle are accessed directly in
> ToStringBuilder instead of through their getters. This prevents subclasses
> from overriding the behavior.
> My proposal is to switch the code to use the getters instead of direct
> field access. This would allow subclasses to provide dynamic behavior, for
> example, returning values based on a logger’s debug level, without needing
> to create a new ToStringStyle instance for every toString() call.
> Before opening a PR, I wanted to discuss this with the community to
> confirm that this approach is acceptable.
> Any thoughts or concerns?
> Note : this is already the case for the 'useIdentityHashCode' field.
> Thanks,
> William
>