Issue Details (XML | Word | Printable)

Key: GROOVY-2342
Type: Sub-task Sub-task
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Hans Dockter
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy
GROOVY-2756

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

Created: 29/Nov/07 02:31 AM   Updated: 16/Oct/08 01:14 PM
Component/s: None
Affects Version/s: 1.1-rc-3
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide

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.



There are no comments yet on this issue.