About String object and pass-by-value in Java -


this question has answer here:

i khow java pass-by-value, , when pass object method , change it,it change when out method. can't string object. example:

public class text  {     public void change(string a)     {         = "ha";     }      public static void main(string[] args)     {         text = new text();         string b = "hi";         a.change(b);         system.out.println(b);     } } 

a = "ha"; 

that statement analogous this:

a = new string("ha"); 

so if string not immutable, you'd have issue pointing a new string object.

what happening here "compiler magic" or "syntactic sugar" make easier declare string.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -