Ok let me simplify the code logic, We have a C++ project and there are at least 100 functions with similar following pattern. I need to convert it into Java code. Then I have some problem
int evaluateFunc(const para1 /*input only*/, para2 &/* input&output*/, para3 & /*output only */ ...)
{
int result = OK;
...
// For Input parameter, we defined as const. e.g. para1
// For Input/Output parameter, we pass either by reference or pointer, as it may get updated during data processing. e.g. para2
// For output only parameter, which will be modified inside function. e.g. para3
...
return result;
}
There are two keys in our evaluateFunc function
- the input/output or output only parameters will be updated by our function as after this function call, these data will be processed by some other function as well. so we use either reference or pointer as parameter and pass to each functions.
- this function need always return an integer value as result to indicate whether this function success or not. e.g. 0 is success, any other integer is error code. WE have a big error list and it could more than 50 different error code. As we have some error handling outside to check this error code and depend the error code to process it accordingly.
Based on my understanding, Java don't support pass by reference or pointer. And all values are passed by copy. Java only can return one value each time which mean if every function need return both error code + some new data (or modified data), then I need create a class for each of them. Unfortunately, the only common part for each function is error code return is expected, all other value return is random. So in the worst case, I need create 100 different class to cover all the different function return result. Is there any generic solution for Java function return result?