title: Java Strings: "String s = new String("silly");"
body: <p>I'm a C++ guy learning Java. I'm reading Effective Java and something confused me. It says never to write code like this:</p>
  
  <pre><code>String s = new String("silly");
  </code></pre>
  
  <p>Because it creates unnecessary <code>String</code> objects. But instead it should be written like this:</p>
  
  <pre><code>String s = "No longer silly";
  </code></pre>
  
  <p>Ok fine so far...However, given this class:</p>
  
  <pre><code>public final class CaseInsensitiveString {
      private String s;
      public CaseInsensitiveString(String s) {
          if (s == null) {
              throw new NullPointerException();
          }
          this.s = s;
      }
      :
      :
  }
  
  CaseInsensitiveString cis = new CaseInsensitiveString("Polish");
  String s = "polish";
  </code></pre>
  
  <ol>
  <li><p>Why is the first statement ok? Shouldn't it be </p>
  
  <p><code>CaseInsensitiveString cis = "Polish";</code></p></li>
  <li><p>How do I make <code>CaseInsensitiveString</code> behave like <code>String</code> so the above statement is OK (with and without extending <code>String</code>)? What is it about String that makes it OK to just be able to pass it a literal like that? From my understanding there is no "copy constructor" concept in Java?</p></li>
  </ol>