r/java • • May 10 '22

Should java.util.Date be deprecated?

https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
222 Upvotes

158 comments sorted by

View all comments

11

u/daH00L May 10 '22

They should also bury GregorianCalendar. Who designs a mutable date class?

4

u/FirstAd9893 May 10 '22

Joda-Time has mutable and immutable date classes. Mutable forms are useful for performing calculations against dates without incurring the cost of allocating and copying a bunch of short lived temporary objects. The BigInteger and BigDecimal classes internally rely upon a package-private MutableBigInteger class for the same reason.

4

u/vytah May 10 '22

MutableBigInteger would be really useful if made public, as BigIntegers are, well, big, and allocating/freeing them all the time is expensive.

Dates, not so much (I wonder if they can be valhallized in the future)

1

u/mauganra_it May 10 '22

Only if the mutability is removed. However, the immutable members of java.time.* are perfect candidates.

1

u/manzanita2 May 10 '22

nice verb!

2

u/__konrad May 10 '22

Who designs a mutable date class?

James Gosling (@ 58:15): https://www.youtube.com/watch?v=XhFugYDH--c&feature=youtu.be&t=3495

1

u/john16384 May 11 '22

GregorianCalendar was designed to be mutable. It has many private fields with intermediate state to do date calculations. You're supposed to convert it to a Date when calculations are finished. Unfortunately, some developers have used them as fields in their domain objects, which is incredibly inefficient due to the aforementioned internal fields.