Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 677513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:02:52+00:00 2026-05-14T01:02:52+00:00

Given that Date has a method called after(Date) and Timestamp has a method the

  • 0

Given that Date has a method called “after(Date)” and Timestamp has a method the overrides it called “after(Timestamp)”, why is the after method in Date called in the following code?

The question as to the unexpected results was asked here.

    java.sql.Timestamp one = new java.sql.Timestamp(1266873627200L);
    java.sql.Timestamp two = new java.sql.Timestamp(1266873627000L);

    java.util.Date oneDate = (java.util.Date) one;
    java.util.Date twoDate = (java.util.Date) two;


    System.out.println("one: " + oneDate.getTime());
    System.out.println("two: " + twoDate.getTime());

    if (oneDate.after(twoDate)) {
        System.out.println(oneDate.getTime() + " after " + twoDate.getTime());
    } else {
        System.out.println(oneDate.getTime() + " not after " + twoDate.getTime());
    }

results

one: 1266873627200
two: 1266873627000
1266873627200 not after 1266873627000
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:02:52+00:00Added an answer on May 14, 2026 at 1:02 am

    Overloads are considered at compile-time; overrides are considered at execution time.

    Timestamp overloads after, it doesn’t override an existing method – so your oneDate.after(twoDate) is only considering the methods in java.util.Date; furthermore even if you use one.after(twoDate) it would still only use after(Date) because the compile-time type of twoDate is Date rather than Timestamp.

    If you call one.after(two) then that will use Timestamp.after(Timestamp).

    Date.after(Date) only considers the milliseconds – but Timestamp only passes an integral number of seconds to the constructor of Date, so oneDate and twoDate have an equal millisecond value in Date, even though you passed different values to the constructors.

    It’s worth noting this bit in the docs for Timestamp though:

    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.

    Sounds like a pretty poor use of inheritance to me, to be honest – but then Java’s got plenty of those 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have function that formats a date to coerce to given enum DateType{CURRENT,
I have a function that get the current weeknumber from the given date e.g.
I have a table that contains records with a column indicates the Date. Given
I have a service that give me a date time string in the following
Given that I have a Foo model w/ the standard Rails timestamp columns what
The method I want to test has a local variable that references an object
I want to create a method for my Activity model that has many Practices
How would I generate a random date that has to be between two other
I'm working on a project that has file uploads. These files are given a
Is that normal that this line: echo date(Y-m-d h:m:s a, strtotime('2012-03-18 12:55:00')) gives me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.