Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: Call by Result Date: Sat, 11 Jun 2011 09:09:05 +0100 Organization: Aioe.org NNTP Server Lines: 30 Message-ID: <1ekbc8-ug2.ln1@news.simpsonst.f2s.com> References: NNTP-Posting-Host: r+C7JLFxs5GRD6HZueZLYg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.22) Gecko/20090605 Lightning/0.9 Thunderbird/2.0.0.22 Mnenhy/0.7.6.666 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5202 On 10/06/11 07:03, Gene Wirchenko wrote: > I am writing a simple preprocessor. I have a few spots where a > string needs to be parsed. I want to call something like this: > String ReturnString=""; > boolean DidItWork=GetString(ReturnString); > if (!DidItWork) > // too bad I don't think the following suggestion has been covered exactly. Split GetString() into two methods: the first testing for the string, storing it in the containing class, and returning true or false; the second simply retrieving the last string. I'm assuming that GetString is non-static for this. class Parser { /** * Attempt to parse a string. If successful, the result * is obtained from {@link #getLastString()}. * * @return true if a string was parsed */ public boolean parseString() { ... } public String getLastString() { ... } } if (parser.parseString()) { doSomethingWith(parser.getLastString()); }