<i18n dev> RFR: 5066247: Refine the spec of equals() and hashCode() for j.text.Format classes

Joe Darcy darcy at openjdk.org
Thu Aug 31 19:04:01 UTC 2023


On Mon, 28 Aug 2023 21:24:18 GMT, Justin Lu <jlu at openjdk.org> wrote:

> Please review this PR which refines the spec of `equals()` and `hashCode()` in `java.text.Format` related classes.
> 
> The current spec for most of these methods is either  "_Overrides <method_name>_" or are incomplete/wrong (i.e. see `ChoiceFormat`).
> 
> This fix adjusts the spec to provide a consistent definition for the overridden methods and specify what is being compared/used to generate a hash code value.
> 
> For implementations that use at most a few fields, the values are stated, otherwise a more general term is used as a substitution (i.e. see `DecimalFormat`).

This class hierarchy is based around a getClass based notion of class identity rather than an instanceof notion of class identity. The drawbacks of doing this are discussed in "Effective Java, 3rd edition" item 10.

Regardless, getClass vs instanceof cannot be changed now for behavioral compatibility. However, this should be better documented so that subclass outside of the JDK could be written to do the right things in their own equals methods.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15459#issuecomment-1701599344


More information about the i18n-dev mailing list