I have developed a very basic approach to deal with this kind of situation.
I have used a logic of seperator in Strings.
For example if you need to return in the same function
1. int value
2. double value
3. String value
you could use a separator string
For example ",.," this kind of string would not generally appear anywhere.
You could return a String consisting of all values separated by this separator
"< int value >,.,< double value >,.,< String value >"
and convert into equivalent types where the function has been called by using String.split(separtor)[index]
Refer the following code for explanation -
separator used =",.,"
public class TestMultipleReturns{
public static void main(String args[]){
String result = getMultipleValues();
int intval = Integer.parseInt(result.split(",.,")[0]);
double doubleval = Double.parseDouble(result.split(",.,")[1]);
String strval = result.split(",.,")[2];
}
public static String getMultipleValues(){
int intval = 231;//some int value
double doubleval = 3.14;//some double val
String strval = "hello";//some String val
return(intval+",.,"+doubleval+",.,"+strval);
}
}
This approach can be used as a shortcut when you do not want to increase number of classes for only function returns
It depends on situation to situation which approach to take.