This is the mail archive of the
frysk@sourceware.org
mailing list for the frysk project.
Re: toPrint vs toString
- From: Kris Van Hees <kris dot van dot hees at oracle dot com>
- To: Sami Wagiaalla <swagiaal at redhat dot com>
- Cc: Andrew Cagney <cagney at redhat dot com>, frysk at sourceware dot org
- Date: Tue, 14 Aug 2007 12:43:18 -0400
- Subject: Re: toPrint vs toString
- References: <46C1C8E8.4060805@redhat.com> <46C1CBC3.4000308@redhat.com>
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