Java – it is not a good practice to use arrays as parameters to return multiple values
I sometimes (actually, often) find myself using a single element array to return multiple values from a method Something like this:
public static int foo(int param1,int param2[],String param3[]) { // method body .... // set return values param2[0] = <some value>; param3[0] = <some value>; return <some value>; }
Is this a bad practice? (it seems that some of my friends said they didn't know what it was doing for 2 seconds!) But the reason I use it first is because it looks closest to the passing reference in C And not discouraged in C, so
But if this is really a wrong way of doing things, how can any idea rewrite it in a clean way?
thank you
Solution
Although I agree with the general comment here that using arrays for this purpose is not a good practice, I would like to add something
Editor: I suggest you search this forum or the Internet for the terms "side effects", "functional programming" or "invariance" This is likely to open up a new perspective for your problem