You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Damir Murat (Jira)" <ji...@apache.org> on 2023/01/10 12:33:00 UTC

[jira] [Resolved] (GROOVY-10899) Problem with the equals operator

     [ https://issues.apache.org/jira/browse/GROOVY-10899?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Damir Murat resolved GROOVY-10899.
----------------------------------
    Resolution: Not A Bug

> Problem with the equals operator
> --------------------------------
>
>                 Key: GROOVY-10899
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10899
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.7
>            Reporter: Damir Murat
>            Priority: Major
>
> I'm unsure if this is a general problem or just something with Uom ([https://github.com/unitsofmeasurement]) reference implementation.
> However, in the following script, the last assertion fails when it should not. I can't tell why, but the equals operator does not end in calling an {{equals()}} method in {{tech.units.indriya.AbstractQuantity}} class as it should. 
>  
> {code:java}
> @Grab('javax.measure:unit-api:2.1.3')
> @Grab('tech.units:indriya:2.1.3')
> import javax.measure.Quantity
> import javax.measure.Unit
> import javax.measure.quantity.Mass
> import tech.units.indriya.quantity.Quantities
> import tech.units.indriya.unit.Units
> Quantity<Mass> quantity1 = Quantities.getQuantity(10, Units.KILOGRAM)
> Quantity<Mass> quantity2 = Quantities.getQuantity(10_000, Units.GRAM)
> println "$quantity1 (${Integer.toHexString(quantity1.hashCode())})"
> println "$quantity2 (${Integer.toHexString(quantity2.hashCode())})"
> assert quantity1 !== quantity2
> assert !quantity1.equals(quantity2)
> // Should not fail, but it does
> assert quantity1 != quantity2
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)