title: Cast int to long in Java
body: <p>This questions has many answers and I have seen them. I have code that has been working but today suddenly it starting throwing <code>java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long</code>
   for the line</p>
  
  <pre><code>return null == input.get(keyName) ? 0L : (long) input.get(keyName);
  </code></pre>
  
  <p>Error is coming from <code>(long) input.get(keyName)</code>. I wonder why it starting breaking all of sudden. <code>(long) input.get(keyName)</code> this looks good to me.
  I thought of doing <code>((Integer) input.get(keyName)).longValue()</code> but was getting <code>java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer</code> as map sometimes contains <code>long</code> values. Any suggestions</p>
  
  <p>Stacktrace:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
      at accountservice.adapter.batch.testJob.SyncDriverPartitioner.getLongValueFromMap(SyncDriverPartitioner.java:78) ~[classes/:?]
      at accountservice.adapter.batch.testJob.SyncDriverPartitioner.partition(SyncDriverPartitioner.java:47) ~[classes/:?]
      at accountservice.adapter.batch.testJob.SyncDriverPartitioner$$FastClassBySpringCGLIB$$6f3315e4.invoke(&lt;generated&gt;) ~[classes/:?]
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.18.RELEASE.jar:4.3.18.RELEASE]
  </code></pre>