title: What is the difference between these two ways of casting in Java?
body: <p>What is the difference between these two ways of casting in Java?</p>
  
  <ol>
  <li><p><code>(CastingClass) objectToCast;</code></p></li>
  <li><p><code>CastingClass.class.cast(objectToCast);</code></p></li>
  </ol>
  
  <p>The source of <code>Class#cast(Object)</code> is as follows:</p>
  
  <pre><code>public T cast(Object obj) {
  if (obj != null &amp;&amp; !isInstance(obj))
      throw new ClassCastException();
  return (T) obj;
  }
  </code></pre>
  
  <p>So, <code>cast</code> is basically a generic wrapper of the cast operation, but I still don't understand why you would need a method for it.</p>