Error “this method must return a result of type int”?

后端 未结 6 2057
攒了一身酷
攒了一身酷 2021-01-28 03:06

I have this code below and it keep telling me that thanksgiving() must return a result type of int. I have casted all the results just to make sure, but nothing seems to be work

6条回答
  •  迷失自我
    2021-01-28 03:45

    The Java compiler is too stupid to realize that in every situation, one of your conditions will be satisfied. It sees the if statements and thinks that it is possible that none of them will be satisfied. You can add a return at the end of the method that indicates an error case, you can throw an exception, or you can assert false.

提交回复
热议问题