I have a method that returns an error code (int) and a result (int). If the error code is 0, the result is valid. In C ++, it might look like this:
int method(int& result);
Java calls by reference, so if we change an object in a method, the change is displayed as the caller. But int is not a class, so I cannot do this in java:
int method(int result);
Both Integer and Long are immutable in Java, so the change is not displayed by the caller if I do it this way:
Integer method(Integer result);
Wrap the result in the Wrapper class! But, it is not so simple!
I have been working with C ++ for a long time and am moving to java, it really bothers me! can anyone provide a solution?
===================================
Well, in conclusion, there are these current solutions:
- pass array as parameter
- pass wrapper as parameter
- return a couple
- ,
- mutableint
1- 2- api
3- 4-
5-, ,
6- ,
!