groovy

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

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1-rc-3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

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.

Activity

There are no comments yet on this issue.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: