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;
}
}
Asked
Active
Viewed 37 times
-1

Konstantin Yovkov
- 62,134
- 8
- 100
- 147

Azhar Mohamed
- 365
- 3
- 11
-
1change callSomething(something); to something=callSomething(something); – pwwpche Jan 21 '15 at 07:44
-
another relevant question: http://stackoverflow.com/questions/1270760/passing-a-string-by-reference-in-java – default locale Jan 21 '15 at 07:45
-
String objects are immutable – EDToaster Jan 21 '15 at 07:49
1 Answers
0
No, in the method, you are changing the reference of the local variable something.
Change your method call to:
something = callSomething(something);

Stultuske
- 9,296
- 1
- 25
- 37