The spec also stated that if one of the operand is String, then both Corec to String. Which rule apply first.
The rules should always be applied in the order they are given in the spec. So the equality
test will perform these in order, executing whichever case it matches first:
A==B (reference comparison)Null checks - returns false if either object is nullIf either are BigDecimal, coerce to BD and A.equals(B)If either are Float or Double, coerce both to Double and applyBigInteger tests are nextByte, Short... Long test are done hereIf either are Boolean (or boolean primitives), coerce to Boolean and applyIf either are Strings, coerce both to String and compare lexically... So:
In the first we have two strings, so we'll compare lexically - and they obviously aren't equal. In the second we have two strings, and again we are testing lexically (although now for > and not for ==), and by the rules of String.compareTo(), we would expect "1" to be 'larger' than "01", as "1" would come after "01" in a dictionary. For line 17 however, one of the terms is a number - and by the list of rules above, numbers are done before strings... so convert "01" to the number 1 and do 1 > 1, which gets the answer false.
In the following example, you can see that if either operand in numeric constant, then the numeric comparision is made, though the other operand is String. So, is there is any rule (precedence) when the value is corec to String or other type.
This is what should happen, because, loosely speaking, numbers are done before strings. I think your second example shows this, but you didn't include the result for line 12, which I think should be true just like line 13. These lines are in fact equivalent, and are both converted to Integers before doing the comparison:
I hope that helps.