Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2756 create new user overwritable operator methods for <,==,>,<=,=>,<==>
  3. GROOVY-2334

== operator uses compareTo instead of equals to calculate its result for Comparable classes

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.1-rc-3
    • None
    • groovy-runtime
    • None

    Description

      This is related to the GString equality issues, but is an issue on its own.

      This might cause nasty side effects.
      
      BigDecimal a = 2.0
      BigDecimal b = 2.00
      
      println a.equals(b) // false
      println(a.compareTo(b)) // 0
      println a == b // true
      
      println([a].equals([b])) // true, which is different from Java, which would return false! 
      

      I think Groovy should try to behave 100 percent like Java in such contexts.

      Attachments

        1. CallCompareToTest.groovy
          0.9 kB
          Ray A. Conner

        Activity

          People

            Unassigned Unassigned
            hans_d Hans Dockter
            Votes:
            10 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated: