4

From the JavaDoc of java.sql.Timestamp class(emphasis mine)

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.

What does it mean to say implementation inheritance and not type inheritance? Is it a case of HAS-A vs IS-A?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Geek
  • 26,489
  • 43
  • 149
  • 227

2 Answers2

5

Basically, the documentation states that the fact that java.sql.Timestamp extends java.util.Date is an implementation detail, and you should not use Timestamp instances where you expect to get Date's functionality. Presumably, if java had the option (like C++ does), Timestamp would privately inherit from Date.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
3

What they mean is that they designed Timestamp as a subclass of Date not to have polymorphism and because a Timestamp is a Date, but because they wanted to easily reuse code from the Date class.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255