RFR: 8311188: Simplify and modernize equals and hashCode in java.text [v3]
Roger Riggs
rriggs at openjdk.org
Wed Jul 5 17:43:03 UTC 2023
On Wed, 5 Jul 2023 16:27:38 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
>> 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.
Just what I wrote; I agree its a toss up from lines of code and performance.
I spotted that style in other files and its just a question of style; your choice.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14752#discussion_r1253433196
More information about the core-libs-dev
mailing list