title: Immutable Types in Java vs. Python
body: <pre><code>String a = new String("Wow");
  String b = new String("Wow");
  String sameA = a;
  
  boolean r1 = a == b;      // This is false, since a and b are not the same object
  boolean r2 = a.equals(b); // This is true, since a and b are logically equals
  boolean r3 = a == sameA;  // This is true, since a and sameA are really the same object
  </code></pre>
  
  <p>Why is this the case? Because strings are immutable, don't <code>a</code> and <code>b</code> point to the same string? For example, if I do the same thing in Python, this is what I get:</p>
  
  <pre><code>a = "wow"
  b = "wow"
  a is b #is True because (I thought) both variables point to the same immutable string
  a == b #is True because they are logically equivalent
  </code></pre>
  
  <p>I'm assuming that Java's == is the same as Python's 'is', and Java's .equals is the same as Python's ==, in which case the two blocks of code contradict each other.</p>
  
  <p>I also have a suspicion that this might have to do w/ the fact that Java doesn't treat Strings as primitives? </p>