Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.utanet.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Newsgroups: comp.lang.java.programmer From: Andreas Leitgeb Subject: Re: Call by Result References: Reply-To: avl@logic.at User-Agent: slrn/pre0.9.9-111 (Linux) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: Date: 11 Jun 2011 15:07:12 GMT Lines: 35 NNTP-Posting-Host: gamma.logic.tuwien.ac.at X-Trace: 1307804832 tunews.univie.ac.at 5640 128.130.175.3 X-Complaints-To: abuse@tuwien.ac.at Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5204 Gene Wirchenko wrote: > On 10 Jun 2011 07:33:12 GMT, Andreas Leitgeb > wrote: >>2) instead of the string, pass a mutable container of a string: >> String[] stringContainer = new String[1]; >> boolean didItWork = getString(stringContainer); >> if (didItWork) { /* stringContainer[0] has the string */ } > > This is a kludge but fairly simple. I did a bit more looking and found > http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html > where a simple class is created. I ended up with I think "kludge" is not the apt term for mine. "hack" may be a better. As you pointed out already, it is equivalent to creating such a container- class, but there's just the tradeoff: - accept some ugliness with "[0]" - add yet another trivial class to your project or to your library's whole interface. Maybe I'm a bad Java-programmer, myself, because I'd go for first, unless there is some domain-related meaning to such a container class, like e.g. "FooState" which would then likely contain more than just one field. >>PS: Surely, someone will soon point out coding-conventions about >> upper-/lower-casing different kinds of identifiers. I dare to agree >> in advance. (Btw., I changed to conformant casing in my examples.) > > I have used a number of languages. One of the things that I > dislike about Java is the small letter first style. It is > particularly bothersome, because my variable naming convention often > has HN-like prefixes. So, actually the method here would be named sGetString(), that's fine with Java's *case*-conventions (but perhaps not with others...)