I was reading Java 8 Date Time API to upgrade my existing code and while going through the various conversion methods like the ones mentioned below to inter operate between the API I was wondering about few things like
- Why all the conversion methods are being provided in the legacy classes for to and fro conversions but not in the new Classes ?
- What could be the rationale behind this Design Decision ?
- Is there any utility class which provides the inter conversion methods?
Instant & Date
Date date = Date.from(instant); // legacy -> new API
Instant instant = date.toInstant(); // API -> legacy
Instant & TimeStamp
TimeStamp time = TimeStamp.from(instant); // legacy -> new API
Instant instant = time.toInstant(); // API -> legacy
LocalDate & Date
Date date = Date.from(localDate); // legacy -> new API
LocalDate localDate = date.toLocalDate(); // API -> legacy
LocalTime & Time
Time time = Time.from(localTime); // legacy -> new API
LocalTime localTime = time.toLocalTime(); // API -> legacy
Aucun commentaire:
Enregistrer un commentaire