title: java.sql.Timestamp comparison bug?
body: <p>Hello I have a code snippet like this:</p>
  <pre><code>Date d1 = new java.sql.Timestamp(new Date().getTime());
  Thread.sleep(10);
  Date d2 = new java.sql.Timestamp(new Date().getTime());
  System.out.println(&quot;Date1: &quot; + d1);
  System.out.println(&quot;Date2: &quot; + d2);
  System.out.println(&quot;Comparing times d1.t &lt; d2.t: &quot; + (d1.getTime() &lt; d2.getTime()));
  System.out.println(&quot;Comparing dates d1.before(d2): &quot; + (d1.before(d2)));
  </code></pre>
  <p>The output looks like this:</p>
  <pre><code>Date1: 2013-03-26 11:04:01.093
  Date2: 2013-03-26 11:04:01.103
  Comparing times d1.t &lt; d2.t: true
  Comparing dates d1.before(d2): false
  </code></pre>
  <p><strong>What's wrong with this java.sql.Timestamp class?</strong></p>
  <p>Yes, I have seen this:</p>
  <blockquote>
  <p>Note: This type is a composite of a java.util.Date and a separate nanoseconds value. Only integral seconds are stored in the java.util.Date component. The fractional seconds - the nanos - are separate. The Timestamp.equals(Object) method never returns true when passed a value of type java.util.Date because the nanos component of a date is unknown. As a result, the Timestamp.equals(Object) method is not symmetric with respect to the java.util.Date.equals(Object) method. Also, the hashcode method uses the underlying java.util.Date implementation and therefore does not include nanos in its computation.</p>
  <p>Due to the differences between the Timestamp class and the java.util.Date class mentioned above, it is recommended that code not view Timestamp values generically as an instance of java.util.Date. The inheritance relationship between Timestamp and java.util.Date really denotes implementation inheritance, and not type inheritance.</p>
  </blockquote>
  <p>But it's for Date &lt;-&gt; Timestamp relation.</p>
  <p>In my example I have Timestamps only, and still the behavior is unexpected..</p>
  <p><strong>UPDATE: ANSWER</strong></p>
  <p>The reason this happens is that <code>before()</code> method is overloaded, not overriden in <code>java.sql.Timestamp</code>.
  I was expecting an 'override' behavior.
  The correct way to compare timestamps is to have Timestamp variables, not Dates.</p>
  <p>This is still a poor design decision in the Java core, since inheritance <em>should</em> mean <strong>Timestamp is-a Date</strong>, with no penalties and exceptions..</p>