Is there some reason to avoid return statements

后端 未结 3 1033
生来不讨喜
生来不讨喜 2021-02-04 01:14

Sometimes I see chunks of Scala code, with several nested levels of conditionals and matchings, that would be much clearer using an explicit return to exit from the function.

3条回答
  •  半阙折子戏
    2021-02-04 02:13

    One drawback is that the return type can't be inferred. Everything else is a matter of style. What seems unclear or confusing to you might be perfectly "natural" to someone else.

提交回复
热议问题