I have a class, lets call it
Calculator, with a method like this:
public double performCalculation(double someInData)
This method can generate a number of non fatal warnings (represented as an array of strings with warning names, such as
InDataOutOfBounds). What is the most elegant and javaesque way to return these warnings to the caller? I see a few possibilities, none that I am particularly fond of:
- Return an instance of a custom class containing both the result of the calculation and the array of warings.
performCalculationaccept an additional argument
String warningsthat it populates with the warnings. This might be a no go, as it seems I can not resize the passed array, and there is no way of knowing in advance how many warnings there will be.
performCalculationas it is, but add a method
Calculator, returning the warnings from the latest calculation.
EDIT: I am aware of this question. I would argue that this is not a duplicate, as the top answer to that question says that the answer is depending on the situation. This is a more specific case, that can get a more specific answer.