About String object and pass-by-value in Java -
this question has answer here:
- immutability of strings in java 23 answers
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
Post a Comment