commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <>
Subject Re: Hierarchies not supported in ToStringBuilder.reflectionToString(this)?
Date Wed, 11 Dec 2002 18:13:57 GMT
[to commons-user, the public forum for lang discussion]

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",

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.


----- Original Message -----
From: "Gary Gregory" <>
> 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

View raw message