We use this method - which is generated by a live template:

        public String toString() {
                StringBuffer sb = new StringBuffer();
                Field[] fields =
IncidentReportEJB.class.getDeclaredFields();
                sb.append( "[ " );
                for ( int i = 0; i < fields.length; i++ ) {
                        try {
                                if ( !Modifier.isStatic(
fields[i].getModifiers() ) ) sb.append( fields[i].getName() ).append( " = "
).append( fields[i].get( this ) ).append( ", " );
                        } catch ( Throwable e ) {
                                e.printStackTrace();
                        }
                }
                sb.append( " ]" );
                return sb.toString();
        }



-----Original Message-----
From: Mike Aizatsky [mailto:[EMAIL PROTECTED]]
Sent: 26 February 2002 13:07
To: [EMAIL PROTECTED]
Subject: RE: [Eap-features] Generate a toString method


James,

Can't you create the small class which will do the same thing via
reflection?

E.g.:

public String toString() { return Util.toString(this); }

Best regards,
Mike Aizatsky.
------------------------------
IntelliJ Software, "Develop with pleasure!" http://www.intellij.com


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:eap-features-
> [EMAIL PROTECTED]] On Behalf Of Jim Birchfield
> Sent: Wednesday, February 20, 2002 7:54 PM
> To: [EMAIL PROTECTED]
> Subject: [Eap-features] Generate a toString method
> 
> I think it would be nice to be able to generate a toString method that
can
> print out all variables.  Something like this:
> 
> private String name;
> private String gender;
> 
> /** IDEA generated */
> public String toString() {
>       StringBuffer buf = new StringBuffer();
>       buf.append("name=");
>       buf.append(name);
>       buf.append(", gender=");
>       buf.append(gender);
>       return buf.toString();
> }
> 
> it would be even nicer to adjust this method when ever variables are
> added,
> subtracted, or changed.
> 
> James Birchfield
> Development Manager
> Genscape, Inc.
> (502) 583-2298 (o)
> (502) 639-3136 (c)
> 
> 
> 
> _______________________________________________
> Eap-features mailing list
> [EMAIL PROTECTED]
> http://www.intellij.com/mailman/listinfo/eap-features


_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-features


***************************************************************************************
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify [EMAIL PROTECTED] 
immediately.

This footnote also confirms that this email message has been swept for the 
presence of computer viruses.
***************************************************************************************

_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-features

Reply via email to