This is the mail archive of the frysk@sourceware.org mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: toPrint vs toString


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]