You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Gary Gregory <gg...@seagullsw.com> on 2002/12/11 20:20:49 UTC

RE: Hierarchies not supported in ToStringBuilder.reflectionToStri ng(this)?

Thank you for the tip Stephen. As far as contributing, I'll see if I can
find some time in the next couple of days. Right now, I have to put out a
fire...

The first question I have towards implementing this is whether or not to
define this as a bug or a feature request WRT backwards compatibility. 

(1) Simplest is sometimes best: This is a bug and reflectionToString() will
handle hierarchies.
(2) More complicated to use and explain: reflectionToString() will
configurable WRT superclasses, perhaps with a toggle in a style class. This
is quite more tricky, since the hook must be provided in the right place. 

So, (1) or (2)?


Thanks,
Gary

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@joda.org]
Sent: Wednesday, December 11, 2002 10:14 AM
To: Jakarta Commons Users List
Cc: Gary Gregory
Subject: Re: Hierarchies not supported in
ToStringBuilder.reflectionToString(this)?


[to commons-user, the public forum for lang discussion]

Gary,
The ToStringBuilder initial version does not support superclass/subclass
relationships at all.

I recently updated the CVS copy of the code so that the manual
ToStringBuilder technique does support superclasses:
  return new ToStringBuilder().appendSuper(super.toString()).append("b",
b).toString();

I also commented the reflectionToString() to indicate that it does not
support superclasses. If you would like to supply a patch to support
superclasses, then this would be welcomed.
http://jakarta.apache.org/site/source.html#Patches

Stephen

----- Original Message -----
From: "Gary Gregory" <gg...@seagullsw.com>
> I have been sprinkeling methods like the following:
>
> public String toString() {
>    return ToStringBuilder.reflectionToString(this);
> }
>
> in our hierachy but I just discovered that this method does not work in a
> class hierarchy!
>
> For example:
>
> class A defines inst var a.
> class B extends A defines inst var b.
>
> new A().toString returns "a=..."
> new B().toString returns "b=..."
>
> when I expected new B().toString to return "a=...,b=..."
>
> Can I use reflectionToString() to accomplish this?
>
> Thank you for considering this request.
>
> Gary
>

Re: Hierarchies not supported in ToStringBuilder.reflectionToString(this)?

Posted by Stephen Colebourne <sc...@btopenworld.com>.
From: "Gary Gregory" <gg...@seagullsw.com>
> The first question I have towards implementing this is whether or not to
> define this as a bug or a feature request WRT backwards compatibility.
>
> (1) Simplest is sometimes best: This is a bug and reflectionToString()
will
> handle hierarchies.
> (2) More complicated to use and explain: reflectionToString() will
> configurable WRT superclasses, perhaps with a toggle in a style class.
This
> is quite more tricky, since the hook must be provided in the right place.

I think #1 should be OK. Superclasses were ignored in the first cut, and
really I think now that was a big bug. For more specific to strings people
have the ability to use the manual fields.

By the way, this affects the HashCode, Equals and CompareTo buiders as well
;-)

Stephen