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

后端 未结 17 1195
清酒与你
清酒与你 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:15

    I use the "tiny class" myself, usually with an inner class. I don't like using arguments to collect messages.

    Also, if the method that might fail is "low level" - like coming from an app server or the database layer, I'd prefer to return an Enum with the return status, and then translate that into a string at the GUI level. Don't pass around user strings at the low level if you're ever going to internationalize your code, because then your app server can only respond in one language at a time, rather than having different clients working in different languages.

提交回复
热议问题