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

Returning a small object with both the boolean flag and the String inside is probably the most OO-like way of doing it, although I agree that it seems overkill for a simple case like this.

Another alternative is to always return a String, and have null (or an empty String – you choose which) indicate success. As long as the return values are clearly explained in the javadocs there shouldn’t be any confusion.

Leave a Comment