I am new to Java, I need to convert C / C ++ code to Java, and I run into obstacles. Due to the way variables are passed to methods, modifying them in a method is not simple, and I have no idea which approach is the most reasonable. Sorry for the pseudo-code examples, I hope they clearly explain what I'm talking about without going into unnecessary details.
I need something that would be equivalent to C
ModifyMyString(type1 &t1,type2 &t2);
(the return type does not matter, it may not be valid), since I need a function to change both t1 and t2.
I can easily change one of the variables, for example, t1, declaring in Java
type1 modifyMyString(type1 t1, type2 t2);
and return value assignment
t1 = modifyMyString(t1,t2);
but this is only half the success, as the new value of t2 is lost.
I can declare a new class
class JustToPassTwoVariables {
type1 t1;
type2 t2;
JustToPassTwoVariables(type1 tt1, type2 tt2) { t1 = tt1; t2 = tt2; }
}
-
JustToPassTwoVariables jtptv = modifyMyString(JustToPassTwoVariables(t1,t2));
, .
modifyMyString , modifyMyString, , JustToPassTwoVariables.
(, , , , ) Java?