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

The compareTo method is not commutative for String and GString when used from Java

    XMLWordPrintableJSON

Details

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

    Description

      Try this Java Code with Java 1.4:

      GString gstring = (GString) new GroovyShell().evaluate("\"${2*2}1\"");
      String string = "41";
      System.out.println(gstring.compareTo(string)); // 0
      System.out.println(string.compareTo(gstring)); // ClassCastException
      

      With Java 1.5 you get a compile error for string.compareTo(gstring), as Comparable uses Generics in Java 5. But still the commutativity is destroyed and it gives you no runtime safety, as we all no.

      This is part of the gstring – string equality discussion.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: