Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.java.programmer > #5334
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Cholo Lennon <chololennon@hotmail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Call by Result |
| Date | Thu, 16 Jun 2011 11:30:22 -0300 |
| Organization | Aioe.org NNTP Server |
| Lines | 77 |
| Message-ID | <itd41d$pjf$1@speranza.aioe.org> (permalink) |
| References | <nkc3v61jg7i21l7n482ce561dq9fdogg3m@4ax.com> |
| NNTP-Posting-Host | FX2JlnghQKkO0dWgQsflYQ.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5334 |
Show key headers only | View raw
On 10/06/2011 03:03, Gene Wirchenko wrote:
> Dear Java'ers:
>
> I wish to call by result with a method. Is it possible? If not,
> can it be easily simulated in an unnasty way?
>
> 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
> It is not acceptable to have a special String value mean failure. I
> want the method to be able to return any potential string.
>
> Sincerely,
>
> Gene Wirchenko
IMHO using exceptions is not always the best answer to this problem (as
other suggested).
How about using a simple generic class? (of course, it could be
corrected or improved. A similar idea could be found in other languages
(such as C++ (boost)):
class Optional<T> {
private T value;
private boolean valid;
public Optional(T value) {
setValue(value);
}
public Optional() {
this.valid = false;
}
public boolean isValid() {
return this.valid;
}
public T getValue() {
return this.value;
}
public void setValue(T value) {
this.value = value;
// TODO Shall I set to true when value is null?
this.valid = true;
}
public void invalidate() {
this.value = null;
this.valid = false;
}
}
// Test
Optional<String> result = GetString();
if (!result.isValid()) {
// too bad
...
}
else {
System.out.print(result.getValue());
...
}
Regards
--
Cholo Lennon
Bs.As.
ARG
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-09 23:03 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 07:33 +0000
Re: Call by Result Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-06-10 10:03 +0100
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 09:47 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-10 08:23 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 13:12 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-10 15:44 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-12 16:29 +0000
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-12 23:00 +0200
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-12 23:06 +0200
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-14 10:52 +0000
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-14 17:13 +0200
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-14 17:58 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-14 21:18 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-14 20:14 -0300
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-15 07:13 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-15 12:50 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-15 18:52 -0300
Re: Call by Result lewbloch <lewbloch@gmail.com> - 2011-06-15 07:06 -0700
Re: Call by Result Michael Wojcik <mwojcik@newsguy.com> - 2011-06-15 21:33 -0400
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-16 11:03 +0000
Re: Call by Result "H.J. Sander Bruggink" <sander.bruggink@uni-due.de> - 2011-06-16 13:09 +0200
Re: Call by Result Lewis Bloch <lewisbloch@google.com> - 2011-06-16 06:59 -0700
Re: Call by Result "John B. Matthews" <nospam@nospam.invalid> - 2011-06-16 23:14 -0400
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:31 -0700
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-12 14:27 -0300
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-10 07:20 -0700
Re: Call by Result Patricia Shanahan <pats@acm.org> - 2011-06-10 09:30 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:44 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:26 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-11 15:07 +0000
Re: Call by Result Abu Yahya <abu_yahya@invalid.com> - 2011-06-11 23:00 +0530
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-11 19:36 +0000
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-11 21:06 +0000
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-12 10:53 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-12 09:28 -0700
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-12 17:48 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-12 13:19 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-11 15:39 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-12 11:07 +0000
Re: Call by Result markspace <-@.> - 2011-06-12 07:02 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-12 09:39 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-14 10:29 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-14 09:14 -0700
Re: Call by Result markspace <-@.> - 2011-06-14 09:21 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-14 09:53 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-14 09:57 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:44 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:40 -0700
Re: Call by Result Patricia Shanahan <pats@acm.org> - 2011-06-10 01:30 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:45 -0700
Re: Call by Result Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-10 07:50 -0400
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-10 15:35 +0200
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 13:56 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-10 07:22 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:56 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:57 -0700
Re: Call by Result Patricia Shanahan <pats@acm.org> - 2011-06-10 13:50 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:53 -0700
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-13 07:20 -0300
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-13 08:08 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-11 16:35 -0700
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-12 11:05 +0000
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:56 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-14 00:40 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-11 21:18 +0000
Re: Call by Result markspace <-@.> - 2011-06-10 08:43 -0700
Re: Call by Result RedGrittyBrick <RedGrittyBrick@spamweary.invalid> - 2011-06-10 17:01 +0100
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-10 16:55 +0000
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:59 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-11 16:24 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:59 -0700
Re: Call by Result Paul Cager <paul.cager@googlemail.com> - 2011-06-13 07:53 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-14 00:43 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:55 -0700
Re: Call by Result Steven Simpson <ss@domain.invalid> - 2011-06-11 09:09 +0100
Re: Call by Result Cholo Lennon <chololennon@hotmail.com> - 2011-06-16 11:30 -0300
Re: Call by Result Paul Cager <paul.cager@googlemail.com> - 2011-06-17 02:38 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-17 12:06 -0700
Re: Call by Result lewbloch <lewbloch@gmail.com> - 2011-06-17 06:40 -0700
Re: Call by Result Cholo Lennon <chololennon@hotmail.com> - 2011-06-17 11:43 -0300
csiph-web