From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14079 invoked by alias); 14 Aug 2007 16:44:14 -0000 Received: (qmail 14070 invoked by uid 22791); 14 Aug 2007 16:44:13 -0000 X-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from agminet01.oracle.com (HELO agminet01.oracle.com) (141.146.126.228) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 14 Aug 2007 16:44:04 +0000 Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l7EGhngR022198; Tue, 14 Aug 2007 11:43:49 -0500 Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id l7EFXQdd026138; Tue, 14 Aug 2007 10:43:49 -0600 Received: from alchar.org by acsmt352.oracle.com with ESMTP id 3126012101187109800; Tue, 14 Aug 2007 09:43:20 -0700 Date: Tue, 14 Aug 2007 16:44:00 -0000 From: Kris Van Hees To: Sami Wagiaalla Cc: Andrew Cagney , frysk@sourceware.org Subject: Re: toPrint vs toString Message-ID: <20070814164318.GB12525@oracle.com> References: <46C1C8E8.4060805@redhat.com> <46C1CBC3.4000308@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46C1CBC3.4000308@redhat.com> User-Agent: Mutt/1.5.16 (2007-06-09) X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE 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/msg00295.txt.bz2 On Tue, Aug 14, 2007 at 11:35:31AM -0400, Sami Wagiaalla wrote: > >> public void toPrint() >> stringWriter = new StringBuffer() >> printWriter = new PrintWriter(stringWriter) >> toPrint(printWriter) >> return stringWriter.toString(); > this should be stringWriter.getBuffer().toString(); Hm, more like: public String toPrint() { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); toPrint(printWriter); return stringWriter.toString(); } because: 1) You cannot pass a StringBuffer to PrinterWriter's contructor 2) StringBuffer doesn't have a getBuffer() method 3) StringWriter has a toString() method 4) You can't return a String from a method that declares its return type as 'void' obviously Either way perhaps it is safer in cases like this to point to existing code (that is known to compile, etc) as an example on how to use specific constructs? Cheers, Kris