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

Non commutative behavior of == operator with Gstring and Integer

    XMLWordPrintableJSON

Details

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

    Description

      int a = 41
      int b = 4
      
      void failsafe(Closure action) {
          try {
              action.call()
          } catch (Throwable e) {
              e.printStackTrace()
          }
      }
      
      GString gs = "${b}1"
      failsafe { println gs == a } // true
      failsafe { println a == gs } // throws ClassCastException
      
      String s = '41'
      failsafe { println a == s } // throws ClassCastException
      failsafe { println s == a } // throws ClassCastException
      

      I haven't attached a testcase as I'm not sure what the right behavior is.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: