Best way to return status flag and message from a method in Java

后端 未结 17 1264
清酒与你
清酒与你 2020-12-25 12:55

I have a deceptively simple scenario, and I want a simple solution, but it\'s not obvious which is \"most correct\" or \"most Java\".

Let\'s say I have a small authe

17条回答
  •  余生分开走
    2020-12-25 13:23

    There are a lot of good answers here so I will keep it short.

    I think failure of a user to authenticate can be considered a valid case for a checked exception. If your style of programming favoured handling exceptions then there would be no reason not to do this. It also removes the "How to return multiple values from a method, my method does one thing It authenticates a user"

    If you are going to return multiple values then spend 10 minutes creating a generic PairTuple (can also be more than a pair TripleTuple, I won't repeat the example listed above) and return your values that way. I hate having small dto style objects to return various multiple values they just clutter the place.

提交回复
热议问题