× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: HTML to XML, vice versa
  • From: "Joe Pluta" <joepluta@xxxxxxxxxxxxxxxxx>
  • Date: Thu, 15 Mar 2001 18:45:55 -0600
  • Importance: Normal

A very important point here is that IDEs (well, VAJ for sure, I haven't used
others enough to make a blanket statement) may call the toString method of
an object when you inspect it.  If your toString method has side effects, or
fails, you can cause some serious problems within your debugger.  So I'm
rethinking my use of toString at all.  It's nearly always the case that you
can't get something for nothing, and a corresponding concept in programming
is that if you code something "cute", taking a shortcut, it's more likely
than not going to bite you in the end.

I already found that a couple of times in Java - early on I used some pretty
"cute" constructors that used the new keyword to create objects that were
used as parameters to my superclass constructor, and while they worked in
JDK1.1, in later releases of the JVM they didn't work so well.  What I
should have done (and now do) is make sure to have setters available for any
parameters passed in the constructor that may need to be instantiated in a
subclass.  I got cute, I got bit.  I can't help but think that overuse of
the toString method falls squarely into the "cute" category.

Joe


> -----Original Message-----
> From: owner-java400-l@midrange.com
> [mailto:owner-java400-l@midrange.com]On Behalf Of Larry Loen
> Sent: Thursday, March 15, 2001 5:44 PM
> To: JAVA400-L@midrange.com
> Subject: RE: HTML to XML, vice versa
>
>
>
> Joe Pluta wrote, in part:
>
> >Instead, you should have a generic toString
>
> and then went on and gave some useful caveats.
>
> The method "toString" is special.  Basically, you should override
> "toString" for any object that needs and deserves a "standard" output
> format to a String.
>
> As a rule of thumb, you should do a "toString" if the following tests are
> met:
>
> 1.  You want or need some sensibly formatted output of the object
> to appear
> in a System.out.println type statement (including the servlet
> equivalents).
> 2.  You have a specific format that "everyone" wants as the String version
> of the object (which is a generalization of the first rule).
>
> For instance, if you had an object like CHexadecimalInteger, then
> you would
> almost certainly have a toString method that returned:
>
> "0x"+((new Integer(myint)).toHexString());
>
> as the implementation of "toString" for CHexadecimalInteger where
> "toHexString()" is the possibly fictitious routine that takes an ordinary
> integer (the CHexadecimalInteger object's "myint" instance variable) and
> turns it into a hexadecimal output string.  PS:  There is a real function
> in Java somewhere that gives a hex string from an integer, but if it isn't
> this one, it is one like it.
>
> Another good example of "toString" is the output you get from an exception
> object.
>
> You'll see it in fragments like this:
>
>    }  /* end 'try' block */ catch (IOException e)  { System.err.println
> ("I/O Exception : "+e.toString()); }
>
>
>
> Larry W. Loen  -   Senior Java and AS/400 Performance Analyst
>                           Dept HP4, Rochester MN
>
>
> +---
> | This is the JAVA/400 Mailing List!
> | To submit a new message, send your mail to JAVA400-L@midrange.com.
> | To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
> | To unsubscribe from this list send email to
> JAVA400-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner: joe@zappie.net
> +---
>

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.