Best practice for returning multiple values in Java?
Not sure about "best practice" but a pragmatic option is to return a Map<String, String>
? 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<String, Object>
and be stricter with type checks on stored objects: Strings, Booleans, Dates, etc.
No, this kind of structure doesn't exists nativily in Java, but you can look at JavaTuples library that may suit your need and provide a quite elegant solution. Using a Triplet<Boolean, String, Boolean>