Best practice for returning multiple values in Java?

前端 未结 7 1217
走了就别回头了
走了就别回头了 2020-12-05 17:31

Today I\'ve added a extra security check behind my login forms, to slow down brute force attacks. I\'ve got multiple login forms and made a nice easy to call function that d

7条回答
  •  感动是毒
    2020-12-05 18:13

    Not sure about "best practice" but a pragmatic option is to return a Map? E.g.

    myMap.put("result", "success");
    myMap.put("usernameConfirmed", "bigTom");
    
    return myMap;
    

    Probably flies in the face of a million OO principles but I hear you re wanting to avoid a proliferation of result classes.

    You could alternatively use Map and be stricter with type checks on stored objects: Strings, Booleans, Dates, etc.

提交回复
热议问题