You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Stephen Colebourne <sc...@joda.org> on 2002/12/11 19:13:57 UTC

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
>