groovy

== uses compareTo if groovy class is a comparable

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    mac 10.5.2 java.1.5 Groovy Version: 1.1-rc-2 JVM: 1.5.0_13-119
  • Number of attachments :
    0

Description

class CP implements Comparable
{
int number

int compareTo(obj)

{ println 'compareTo called' return number - obj.number }

boolean equals(obj)

{ println 'equals called' return obj.number = number }

}

// script
def cp1 = new CP(number:1)
def cp2 = new CP(number:2)
cp1==cp2

// results
if CP implements Comparable, compareTo is called, if not, equals is called

// using grails with above as follows has ominous implications

I have a setup similar to as follows:
TopLevelDomainClass

{ SortedSet subLevels static hasMany= [subLevels:SubLevelDomainClass] }

SubLevelDomainClass implements Comparable
{
int number
int compareTo(obj)

{ return this.number - obj.number }

}

sublevel1==sublevel2 calls the compareTo function for evaluation

Activity

Hide
Alberto Brandolini added a comment -

I am on a Mac too, and I run into the same issue, when I changed my classes to implement the Comparable interface.

I suspect the OS isn't to be blamed, since this bug looks a lot like
http://jira.codehaus.org/browse/GROOVY-2334

I'll do some checks on a different OS anyway.

Show
Alberto Brandolini added a comment - I am on a Mac too, and I run into the same issue, when I changed my classes to implement the Comparable interface. I suspect the OS isn't to be blamed, since this bug looks a lot like http://jira.codehaus.org/browse/GROOVY-2334 I'll do some checks on a different OS anyway.

People

Vote (5)
Watch (6)

Dates

  • Created:
    Updated: