In C#, the value in it is changed when called in the secondary function, and the main function will also change.
The ref keyword causes the parameters to be passed by reference. The effect is that when control is passed back to the call method, any changes made to the parameters in the method will be reflected in the variable. To use the ref parameter, both the method definition and the method calling must use the ref keyword explicitly.
The out keyword causes the parameters to be passed by reference. This is similar to the ref keyword, except that ref requires that variables must be initialized before being passed. To use the out parameter, both the method definition and the method calling must use the out keyword explicitly.
Java is not like C#. Java only has object type parameters that pass addresses. When Java's basic type variables make parameters, they only pass values.
The solution is to use Java classes as the parameter type of the function.
Here is an example I wrote:
File name: byRefVariable.java
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- System.out.println("test is passed as a parameter to changeIt"+test.var); } public static void changeIt(obj a) { a.var=12580; } } class obj //I have defined a class here. { int var=0;}The above is all the content of the method of implementing the C# syntax by reference in Java that the editor brings to you. I hope it will be helpful to everyone and support Wulin.com more~