It's common knowledge that java.util.Date
has undesireable qualities and should be avoided whenever possible by developers, especially now that a proper Date/Time API exists within Java SE. Despite its faults, however, there are actually some features of the Groovy language that may be encouraging the continued use of java.util.Date
.
1. It is always imported
Groovy imports the java.util
package by default because, more often than not, code will need something defined within that package. Date, of course, being in that package, becomes readily available for use. I've become accustomed to invoking new Date()
and Date.parse(dateStr)
without even thinking about my import statements.
The Java 8 Date/Time API is a different story. I often write my Groovy scripts without a full-featured IDE, so I have to manually add imports--usually after som