title: Java: comparing two Objects of different type with same value, returning true
body: <p>I have some data I need to compare. It's possible I might have to compare values with different data types. Here is what is basically happening:</p>
  
  <pre><code>Object a = (long) 1;
  Object b = (int) 1;
  
  
  System.out.println(Objects.equals(a, b)); //returns false
  
  Sysout.out.println(Objects.equals(a.toString(), b.toString())); //returns true
  </code></pre>
  
  <p>Does using .toString() seem like a viable solution? Or should I go another route ?</p>
  
  <p>Edit:</p>
  
  <p>This program is reading from HIVE tables which some tables might have the exact same data in it, but different datatypes. Datatypes include int, smallint, bigint, string, array, double, timestamp.</p>
  
  <p>I'm not concerned with the Array comparison, because there's nothing other than the array type that can hold an array. However, it is possible for String types to be compared with timestamp. I'm also not concerned with int to double comparisons either, because these should result in false.</p>
  
  <p>Any numerical value with no decimal places and different datatypes should be compared with their value and datatype mismatch should not return false.</p>
  
  <p>Edit:</p>
  
  <p>Any number with decimals will be rounded with 3 decimal places before comparison.</p>