public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Kris Van Hees <kris.van.hees@oracle.com>
To: Sami Wagiaalla <swagiaal@redhat.com>
Cc: Andrew Cagney <cagney@redhat.com>, frysk@sourceware.org
Subject: Re: toPrint vs toString
Date: Tue, 14 Aug 2007 16:44:00 -0000	[thread overview]
Message-ID: <20070814164318.GB12525@oracle.com> (raw)
In-Reply-To: <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

  reply	other threads:[~2007-08-14 16:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-14 15:23 Andrew Cagney
2007-08-14 15:35 ` Sami Wagiaalla
2007-08-14 16:44   ` Kris Van Hees [this message]
2007-08-14 17:12   ` Sami Wagiaalla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070814164318.GB12525@oracle.com \
    --to=kris.van.hees@oracle.com \
    --cc=cagney@redhat.com \
    --cc=frysk@sourceware.org \
    --cc=swagiaal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).