< prev index next >

src/java.base/share/classes/java/time/MonthDay.java

Print this page

100  * This class does not store or represent a year, time or time-zone.
101  * For example, the value "December 3rd" can be stored in a {@code MonthDay}.
102  * <p>
103  * Since a {@code MonthDay} does not possess a year, the leap day of
104  * February 29th is considered valid.
105  * <p>
106  * This class implements {@link TemporalAccessor} rather than {@link Temporal}.
107  * This is because it is not possible to define whether February 29th is valid or not
108  * without external information, preventing the implementation of plus/minus.
109  * Related to this, {@code MonthDay} only provides access to query and set the fields
110  * {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH}.
111  * <p>
112  * The ISO-8601 calendar system is the modern civil calendar system used today
113  * in most of the world. It is equivalent to the proleptic Gregorian calendar
114  * system, in which today's rules for leap years are applied for all time.
115  * For most applications written today, the ISO-8601 rules are entirely suitable.
116  * However, any application that makes use of historical dates, and requires them
117  * to be accurate will find the ISO-8601 approach unsuitable.
118  * <p>
119  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
120  * class; programmers should treat instances that are
121  * {@linkplain #equals(Object) equal} as interchangeable and should not
122  * use instances for synchronization, or unpredictable behavior may
123  * occur. For example, in a future release, synchronization may fail.
124  * The {@code equals} method should be used for comparisons.







125  *
126  * @implSpec
127  * This class is immutable and thread-safe.
128  *
129  * @since 1.8
130  */
131 @jdk.internal.ValueBased

132 public final class MonthDay
133         implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {
134 
135     /**
136      * Serialization version.
137      */
138     @java.io.Serial
139     private static final long serialVersionUID = -939150713474957432L;
140 
141     /**
142      * For backward compatibility of the serialized {@code MonthDay.class} object,
143      * explicitly declare the types of the serialized fields as defined in Java SE 8.
144      * Instances of {@code MonthDay} are serialized using the dedicated
145      * serialized form by {@code writeReplace}.
146      * @serialField month int The month-of-year.
147      * @serialField day int The day-of-month.
148      */
149     @Serial
150     private static final ObjectStreamField[] serialPersistentFields = {
151             new ObjectStreamField("month", int.class),

100  * This class does not store or represent a year, time or time-zone.
101  * For example, the value "December 3rd" can be stored in a {@code MonthDay}.
102  * <p>
103  * Since a {@code MonthDay} does not possess a year, the leap day of
104  * February 29th is considered valid.
105  * <p>
106  * This class implements {@link TemporalAccessor} rather than {@link Temporal}.
107  * This is because it is not possible to define whether February 29th is valid or not
108  * without external information, preventing the implementation of plus/minus.
109  * Related to this, {@code MonthDay} only provides access to query and set the fields
110  * {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH}.
111  * <p>
112  * The ISO-8601 calendar system is the modern civil calendar system used today
113  * in most of the world. It is equivalent to the proleptic Gregorian calendar
114  * system, in which today's rules for leap years are applied for all time.
115  * For most applications written today, the ISO-8601 rules are entirely suitable.
116  * However, any application that makes use of historical dates, and requires them
117  * to be accurate will find the ISO-8601 approach unsuitable.
118  * <p>
119  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
120  * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
121  * as interchangeable and should not use instances for synchronization, mutexes, or
122  * with {@linkplain java.lang.ref.Reference object references}.
123  *
124  * <div class="preview-block">
125  *      <div class="preview-comment">
126  *          When preview features are enabled, {@code MonthDay} is a {@linkplain Class#isValue value class}.
127  *          Use of value class instances for synchronization, mutexes, or with
128  *          {@linkplain java.lang.ref.Reference object references} result in
129  *          {@link IdentityException}.
130  *      </div>
131  * </div>
132  *
133  * @implSpec
134  * This class is immutable and thread-safe.
135  *
136  * @since 1.8
137  */
138 @jdk.internal.ValueBased
139 @jdk.internal.MigratedValueClass
140 public final class MonthDay
141         implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {
142 
143     /**
144      * Serialization version.
145      */
146     @java.io.Serial
147     private static final long serialVersionUID = -939150713474957432L;
148 
149     /**
150      * For backward compatibility of the serialized {@code MonthDay.class} object,
151      * explicitly declare the types of the serialized fields as defined in Java SE 8.
152      * Instances of {@code MonthDay} are serialized using the dedicated
153      * serialized form by {@code writeReplace}.
154      * @serialField month int The month-of-year.
155      * @serialField day int The day-of-month.
156      */
157     @Serial
158     private static final ObjectStreamField[] serialPersistentFields = {
159             new ObjectStreamField("month", int.class),
< prev index next >