Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39008

Re: Java missing return statement question...

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Andreas Leitgeb <avl@logic.at>
Newsgroups comp.lang.java.programmer
Subject Re: Java missing return statement question...
Date Thu, 18 Jul 2019 13:44:36 -0000 (UTC)
Organization A noiseless patient Spider
Lines 32
Message-ID <slrnqj0tu4.36g.avl@logic.at> (permalink)
References <67615856-0be2-4c3f-ae4c-c9f3cb379451@googlegroups.com>
Reply-To avl@logic.at
Injection-Date Thu, 18 Jul 2019 13:44:36 -0000 (UTC)
Injection-Info reader02.eternal-september.org; posting-host="49eb6b260a2157687ff97d3d05d2993d"; logging-data="18695"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189TJo81OnrTBiW+4HTA5u3"
User-Agent slrn/1.0.3 (Linux)
Cancel-Lock sha1:poHj6BF/zNxP/GxEq7E7dBxQ9Tc=
Xref csiph.com comp.lang.java.programmer:39008

Show key headers only | View raw


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


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