Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
why ZonedDateTime class does not implement TemporalAdjuster interface

I'm currently studying java.time API and I have noticed that majority of class (e.g. LocalDate, OffsetDateTime) in java.time implement TemporalAdjuster interface, but ZonedDateTime does not. I was just wondering why this is the case? Why exclude ZonedDateTime from implementing TemporalAdjuster interface?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

A TemporalAdjuster changes another temporal object via the TemporalAdjuster.adjustInto(Temporal) method. The Temporal interface allows the individual fields to be altered via Temporal.with(TemporalField, long).

LocalDate can implement TemporalAdjuster because its state consists entirely of temporal fields (year, month, day-of-month). As such, the implementation in LocalDate.adjustInto(Temporal) can call Temporal.with(TemporalField, long) passing the year, month and day (it actually uses ChronoField.EPOCH_DAY, which is a composite of year, month and day).

OffsetDateTime can implement TemporalAdjuster because its state also consists entirely of temporal fields (year, month, day-of-month, hour, minute, second, nanosecond and offset-seconds). Thus, again the implementation in OffsetDateTime.adjustInto(Temporal) can call Temporal.with(TemporalField, long) passing the fields one-by-one.

ZonedDateTime cannot implement TemporalAdjuster because its state includes a ZoneId, which is not a temporal field, thus cannot be passed to Temporal.with(TemporalField, long). ie. it is not possible to change the time-zone of a temporal class via the Temporal interface.

Given that ZonedDateTime includes all the possible date-time fields, this restriction has little effect in practice.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda