title: Variable's scope in a switch case
body: <p>I think I don't understand how the scope works in a switch case.</p>
  
  <p>Can someone explain to me why the first code doesn't compile but the second does ?</p>
  
  <p>Code 1 :</p>
  
  <pre><code> int key = 2;
   switch (key) {
   case 1:
        String str = "1";
        return str;
   case 2:
        String str = "2"; // duplicate declaration of "str" according to Eclipse.
        return str;
   }
  </code></pre>
  
  <p>Code 2 :</p>
  
  <pre><code> int key = 2;
   if (key == 1) {
        String str = "1";
        return str;
   } else if (key == 2) {
        String str = "2";
        return str;
   }
  </code></pre>
  
  <p>How come the scope of the variable "str" is not contained within Case 1 ?</p>
  
  <p>If I skip the declaration of case 1 the variable "str" is never declared...</p>