<i18n dev> RFR: 8311188: Simplify and modernize equals and hashCode in java.text [v2]

Pavel Rappo prappo at openjdk.org
Wed Jul 5 16:35:13 UTC 2023


On Wed, 5 Jul 2023 15:47:56 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Pavel Rappo has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Adhere to surrounding code style
>
> src/java.base/share/classes/java/text/DecimalFormat.java line 2926:
> 
>> 2924:         if (obj == this) { // disambiguate super equality from ref equality
>> 2925:             return true;
>> 2926:         }
> 
> Ditto comment in CompactNumberFormat.

Fixed this and the other one in b338480e540.

> src/java.base/share/classes/java/text/DecimalFormat.java line 2930:
> 
>> 2928:         DecimalFormat other = (DecimalFormat) obj;
>> 2929:         return ((posPrefixPattern == other.posPrefixPattern &&
>> 2930:                  positivePrefix.equals(other.positivePrefix))
> 
> This might also be:
> 
> return (obj instanceof DecimalFormat other) && 
>                  posPrefixPattern == other.posPrefixPattern &&
>                  positivePrefix.equals(other.positivePrefix));

Do you mean we could use `obj instanceof DecimalFormat other` in front of that 30-line `&&` expression, or that we could collapse the list to exactly what you wrote?

Separately, `super.equals` already performs the class check; so enhanced `instanceof` could be used only as a syntactic sugar, but even then it won't decrease the line count: we trade one line for another very similar line.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14752#discussion_r1253358517
PR Review Comment: https://git.openjdk.org/jdk/pull/14752#discussion_r1253357171


More information about the i18n-dev mailing list