commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <ggreg...@seagullsw.com>
Subject RE: Hierarchies not supported in ToStringBuilder.reflectionToStri ng(this)?
Date Wed, 11 Dec 2002 19:20:49 GMT
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" <ggregory@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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message