Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39011
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java missing return statement question... |
| Date | 2019-07-18 13:47 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <qgqbbl$d98$1@dont-email.me> (permalink) |
| References | <67615856-0be2-4c3f-ae4c-c9f3cb379451@googlegroups.com> |
On 7/18/2019 9:29 AM, cdalten@gmail.com wrote:
> I don't quite understand why something like the following gives a missing return statement.
Andreas Leitgeb has already answered your main question. I'd
just like to point out one additional oddity:
> if (noDoubles == true) {
You begin with the boolean `noDoubles', which (necessarily) has one
of the values `true' or `false'. You want to find out whether the value
is `true', so you compare it to `true' -- and since the comparison
produces either `true' or `false', you have made no "progress." That
is, you *still* have a value that is either `true' or `false', exactly
as you did before making the comparison. What next?
You could continue by writing
if ((noDoubles == true) == true) {
... but you're still in the same situation, so onward to
if (((noDoubles == true) == true) == true) {
... but that's still no help, either. You could try something
along the lines of
if ((((noDoubles == true) == false) != true) == true) {
... but somehow I don't see this line of attack getting anywhere.
"Anywhere useful," that is.
Instead, consider
if (noDoubles) {
... and your Note To Self For Future Reference should be: "It may,
rarely, make sense to compare two boolean values, but comparing a
boolean to a constant never makes sense."
--
esosman@comcast-dot-net.invalid
Five hundred fifty-two days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Java missing return statement question... cdalten@gmail.com - 2019-07-18 06:29 -0700
Re: Java missing return statement question... Andreas Leitgeb <avl@logic.at> - 2019-07-18 13:44 +0000
Re: Java missing return statement question... cdalten@gmail.com - 2019-07-18 06:54 -0700
Re: Java missing return statement question... Eric Douglas <e.d.programmer@gmail.com> - 2019-07-18 07:51 -0700
Re: Java missing return statement question... Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-07-18 13:47 -0400
csiph-web