Source of TestStringImmutability.java


  1: // TestStringImmutability.java

  3: class Thing
  4: {
  5:    int i;
  6: }

  8: public class TestStringImmutability
  9: {

 11:     public static void main(String[] args)
 12:     {
 13:         Thing t = new Thing();
 14:         t.i = 3;
 15:         System.out.println("t.i in main: " + t.i);
 16:         DoThing(t);
 17:         System.out.println("t.i in main: " + t.i);

 19:         String s = "Hello";
 20:         s += " there!";
 21:         System.out.println("s in main: " + s);
 22:         DoString(s);
 23:         System.out.println("s in main: " + s);
 24:     }


 27:     static void DoThing(Thing t)
 28:     {
 29:         t.i += 7;
 30:         System.out.println("t.i inside DoThing: " + t.i);
 31:     }


 34:     static void DoString(String s)
 35:     {
 36:         s += " How are you?";
 37:         System.out.println("s inside DoString: " + s);
 38:     }
 39: }