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.Let performCalculation accept an additional argument String[] warnings that 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.Keep performCalculation as it is, but add a method String[] getWarnings() to 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.
How to return warnings alongside result of calculation to caller of a Java method?
java;object oriented;return type
Yes. Do this. It's Java, do not fear classes. This is what classes are for.Really bad. It is slightly less bad with a Collection instead of an array, but you're still asking for ad-hoc ill-specified semantics that will never be used quite right.Can work if you are absolutely, positively certain that you will never, ever use Calculator except in a single-flow-of-control situation. Unfortunately, parallelizing things is one of the more common changes required after the fact.