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

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

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