From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13453 invoked by alias); 14 Aug 2007 15:23:23 -0000 Received: (qmail 13219 invoked by uid 22791); 14 Aug 2007 15:23:21 -0000 X-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_50,DK_POLICY_SIGNSOME,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 14 Aug 2007 15:23:15 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l7EFNBX6020233 for ; Tue, 14 Aug 2007 11:23:11 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l7EFNBMR027904 for ; Tue, 14 Aug 2007 11:23:11 -0400 Received: from [127.0.0.1] (sebastian-int.corp.redhat.com [172.16.52.221]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l7EFNA0U006692 for ; Tue, 14 Aug 2007 11:23:11 -0400 Message-ID: <46C1C8E8.4060805@redhat.com> Date: Tue, 14 Aug 2007 15:23:00 -0000 From: Andrew Cagney User-Agent: Thunderbird 1.5.0.12 (X11/20070530) MIME-Version: 1.0 To: frysk@sourceware.org Subject: toPrint vs toString Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q3/txt/msg00292.txt.bz2 toString(): for dumping internal object state --------------------------------------------- Just a reminder; Java's Object class includes a <> method that can be overridden (by default it prints the object's address and type) to dump out an objects internal state. That way, when printing or tracing this method is called vis: System.out.println("my " + task); // uses Task.toString logger.log(Level.FINE, "{0} task\n", task); // ditto and debugging level information is provided. However, within frysk, toString() or variations shouldn't be used when creating output intended for the user. toPrint(): for displaying an object user friendly ------------------------------------------------- If the output is intended for the user, the add a toPrint() method and use that. There are two variations. The first sends the output to a Writer vis: public void toPrint(PrintWriter writer) ... writer.print ... and the second, if you find it necessary, just wraps the first vis: public void toPrint() stringWriter = new StringBuffer() printWriter = new PrintWriter(stringWriter) toPrint(printWriter) return stringWriter.toString(); For instance, frysk.value.Value as methods such as: public void toPrint(PrintWriter writer, ByteBuffer memory, Format format) public String toPrint() { ... see above ... } for converting a value in to a user-readable form.