title: How to convert object to long data type java
body: <p>I have this code which gives me an error?</p>
  
  <pre><code>public int part(Object key) {   
      long clientId = (long) key;
      ...
  }
  </code></pre>
  
  <p>Below is the error:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
  </code></pre>
  
  <p>Not sure why it throws an exception.</p>