title: Casting Object to String v/s Casting object to Character
body: <p>I have a generic implementation of a Stack. An object of this Stack has the name stak and is of the type <code>Character</code>.</p>
  
  <p>I tried</p>
  
  <pre><code>if ( ( ((String)(stak.head).equals("{")) &amp;&amp; (str.charAt(i)=='}') )  { /* do something */}
  </code></pre>
  
  <p>The code compiles correctly but it gives me following error on runtime:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.Character can
  not be cast to java.lang.String
          at One.main(One.java:36)
  </code></pre>
  
  <p>However, the following code works:</p>
  
  <pre><code>if ( ((Character)(stak.head) == '{') &amp;&amp; (str.charAt(i)=='}') )  { /* do something */}
  </code></pre>
  
  <p>Can you please explain why doesn't the character object get cast into String?</p>