tags:

views:

489

answers:

2

The title says it all. Java.sql.date extends java.util.date, so is it save to convert between the two by casting a java.sql.date as a java.util.date? Or is there some other way to convert them?

+1  A: 

Yes, you can just upcast it.

The java.sql.Date is in fact nothing less or more than a representation of the SQL Date type, which has only year, month and day filled.

BalusC
What was that downvote about? :D
BalusC
+3  A: 

You don't necessarily need to cast, you can just treat a SQL Date as if it was a util Date:

java.sql.Date sqlDate = new java.sql.Date(whenever);
java.util.Date utilDate = sqlDate;

Compiles and runs just fine.

mattjames