s**n 发帖数: 178 | 1 f1()
{
String s1 = null;
f2(s1);
System.out.println(s1);
}
f2(String str)
{
str=f3();
}
In f2(), str can not pass back the string back to s1 in f1(), because of
pass-by-value. How to get the string from f2() besides using return? |
g*****g 发帖数: 34805 | 2 just use return, or you can use collection or object wrapper.
【在 s**n 的大作中提到】 : f1() : { : String s1 = null; : f2(s1); : System.out.println(s1); : } : f2(String str) : { : str=f3(); : }
|
s**n 发帖数: 178 | 3 Thanks. In my case, I need get back two strings, I use string array to do it
. Is there any better ways?
【在 g*****g 的大作中提到】 : just use return, or you can use collection or object wrapper.
|
A**o 发帖数: 1550 | 4 define a structure (i.e. a pojo)
it
【在 s**n 的大作中提到】 : Thanks. In my case, I need get back two strings, I use string array to do it : . Is there any better ways?
|
a****l 发帖数: 8211 | 5 return an object that contains this string, or pass in an object that
contains this string.
【在 s**n 的大作中提到】 : f1() : { : String s1 = null; : f2(s1); : System.out.println(s1); : } : f2(String str) : { : str=f3(); : }
|
c********g 发帖数: 449 | |