Skip to main content



      Home
Home » Newcomers » Newcomers » Generating a toString method
Generating a toString method [message #265350] Thu, 09 October 2008 16:06 Go to next message
Eclipse UserFriend
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 #265352 is a reply to message #265350] Thu, 09 October 2008 16:24 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------000701020308020600040509
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Dave,

I'm not sure there is a way yet. Someone was working on it though:

http://wiki.eclipse.org/ToString()_generation
<http://wiki.eclipse.org/ToString%28%29_generation>



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
>

--------------000701020308020600040509
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Dave,<br>
<br>
I'm not sure there is a way yet.
Re: Generating a toString method [message #265354 is a reply to message #265350] Thu, 09 October 2008 16:45 Go to previous message
Eclipse UserFriend
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
Previous Topic:Eclipse using 700 RAM!?
Next Topic:adding JEE support to classic package
Goto Forum:
  


Current Time: Fri May 02 09:30:24 EDT 2025

Powered by FUDForum. Page generated in 0.08136 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top