Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39008
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java missing return statement question... |
| Date | 2019-07-18 13:44 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnqj0tu4.36g.avl@logic.at> (permalink) |
| References | <67615856-0be2-4c3f-ae4c-c9f3cb379451@googlegroups.com> |
cdalten@gmail.com <cdalten@gmail.com> wrote:
> I don't quite understand why something like the following gives a missing return statement.
> public int withoutDoubles(int die1, int die2, boolean noDoubles) {
> if (die1 != die2) {
> return die1 + die2;
> }
Since furtheron obviously die1==die2, the following part of code
seems needlessly overcomplicated.
>
> if (noDoubles == true) {
> if ((die1 == die2) && (die1 != 6 || die2 != 6)) {
> return (die1 + die2) + 1;
> } else if (die1 == 6 || die2 == 6) {
> return die1 + 1;
> }
Because ^ here is one "branch" that doesn't currently return.
I mean the "else if"'s (missing) "else" case, where
noDoubles == true is true
(die1 == die2) && (die1 != 6 || die2 != 6) is false
die1 == 6 || die2 == 6 is false
As a human, we can see, that this combination cannot happen
due to equal dice, but apparently the Java compiler cannot.
> } else {
> return die1 + die2;
> }
> }
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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