groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Josef (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-7954) Equal Operator for Classes implementing Comparable not Working on Interfaces
Date Thu, 06 Oct 2016 07:27:21 GMT

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

Josef updated GROOVY-7954:
--------------------------
    Attachment: Example.zip

Please find attached a simple example project (main class: Example.groovy).
Thanks.

> Equal Operator for Classes implementing Comparable not Working on Interfaces
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-7954
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7954
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>         Environment: Windows 10, Java 7
>            Reporter: Josef
>         Attachments: Example.zip
>
>
> Using the equal operator "==" on two instances A and B does not work correctly, when
> 1) A and B implement the same interface I1 but are not the same class and
> 2) interface I1 extends the "Comparable" interface.
> The checking in DefaultTypeTransformation.compareToWithEqualityCheck(...) checks for
assignable classes, and uses compareTo when assignable on class level (which is not the case
for instance A and B). But it does not check on interface level.
> That way, calling the compareTo(..) method is not performed.
> In my use case, class A and B are actually considered equal, even so their concrete implementation
is different. And the compareTo(...) method would actually return 0. 
> How about doing real equality checking instead of returning -1 close to the end of method
DefaultTypeTransformation.compareToWithEqualityCheck(...):
> ...
> if (equalityCheckOnly) {
>     return left.equals(right) ? 0 : -1;
> }
> throw new GroovyRuntimeException("Cannot compare " + left.getClass().getName() + " with
value '" +
>                 left + "' and " + right.getClass().getName() + " with value '" + right
+ "'");
> Thanks for your effort.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message