Generating a toString method [message #265350] |
Thu, 09 October 2008 16:06  |
Eclipse User |
|
|
|
Hi,
I'm using Eclipse 3.4 on Windows XP. Is there a way I can auto-generate a
toString method that prints out each field name in my Java class? I have
a class with 20 fields and it will be a pain to type them all out by hand,
but if I have to, I have to.
Let me know your thoughts. Thanks, - Dave
|
|
|
|
Re: Generating a toString method [message #265354 is a reply to message #265350] |
Thu, 09 October 2008 16:45  |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Dave Alvarado wrote:
> Hi,
>
> I'm using Eclipse 3.4 on Windows XP. Is there a way I can auto-generate
> a toString method that prints out each field name in my Java class? I
> have a class with 20 fields and it will be a pain to type them all out
> by hand, but if I have to, I have to.
>
> Let me know your thoughts. Thanks, - Dave
>
There is a Google Summer of Code project to implement this in Eclipse.
See
http://eclipse-n-mati.blogspot.com/2008/08/tostring-generato r-plug-in.html
and https://bugs.eclipse.org/bugs/show_bug.cgi?id=26070
There is also the very useful Apache/Jakarta class ToStringBuilder, part
of the Jakarta Commons Lang library: http://commons.apache.org/lang/
The benefit of that is that it does not require installing anything into
your Eclipse; it is a simple API for implementing toString() methods
with 1 or 2 lines of code, that don't have to be updated when the fields
of your class change.
Hope this helps,
Eric
|
|
|
Powered by
FUDForum. Page generated in 0.08136 seconds