2015-01-21 69 views
-1
package com.mkyong.test; 

public class Main { 

    public static void main(String[] args) { 
     String something = ""; 
     callSomething(something); 

     System.out.println(something); 
    } 

    private static String callSomething(String something) { 
     something = "Hello Wrold !"; 
     return something; 
    } 
} 
+1

变化callSomething(东西); to something = callSomething(something); – pwwpche 2015-01-21 07:44:06

+0

另一个相关的问题:http://stackoverflow.com/questions/1270760/passing-a-string-by-reference-in-java – 2015-01-21 07:45:10

+0

字符串对象是不可变的 – JClassic 2015-01-21 07:49:06

回答

0

不,在该方法中,您正在改变局部变量的引用。

你的方法调用更改为:

something = callSomething(something);