Class Years

java.lang.Object
cloud.opencode.base.date.extra.Years
All Implemented Interfaces:
Serializable, Comparable<Years>, TemporalAmount

public final class Years extends Object implements TemporalAmount, Comparable<Years>, Serializable
Years unit class representing a number of years 年数单位类,表示年数

This class represents a number of years, similar to Period but focused on the years unit. It implements TemporalAmount for use with java.time.

此类表示年数,类似于Period但专注于年单位。实现TemporalAmount以与java.time配合使用。

Features | 主要功能:

  • Type-safe years representation - 类型安全的年数表示
  • Arithmetic operations (plus, minus, multiply, divide) - 算术操作(加、减、乘、除)
  • Conversion to Period, Months - 转换为Period、Months
  • TemporalAmount implementation for java.time integration - 实现TemporalAmount以集成java.time

Usage Examples | 使用示例:

Years y = Years.of(5);
Months m = y.toMonths();  // 60 months
Period p = y.toPeriod();
LocalDate date = LocalDate.now().plus(y);

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Overflow-safe: Yes (uses Math.addExact/multiplyExact) - 溢出安全: 是(使用Math.addExact/multiplyExact)
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: